Skip to main content

getTangentAtLength()

属于@remotion/paths包。

获取位于SVG路径上的点的切线值xy。第一个参数是SVG路径,第二个参数是应该采样点的长度。它必须介于0和getLength()的返回值之间。

如果路径有效,则返回一个点:

tsx
import { getTangentAtLength } from "@remotion/paths";
 
const tangent = getTangentAtLength("M 50 50 L 150 50", 50);
console.log(tangent); // { x: 1, y: 0}
tsx
import { getTangentAtLength } from "@remotion/paths";
 
const tangent = getTangentAtLength("M 50 50 L 150 50", 50);
console.log(tangent); // { x: 1, y: 0}

如果路径无效,则该函数将抛出异常:

tsx
getTangentAtLength("remotion", 50); // Error: Malformed path data: ...
tsx
getTangentAtLength("remotion", 50); // Error: Malformed path data: ...

Credits

源代码主要来自svg-path-properties

另请参阅