【发布时间】:2019-10-18 21:19:30
【问题描述】:
我有这个 SVG 文件
我想知道直线的方程。可能吗?我需要方程式在这条线上的不同位置动态添加一些 SVG 点。所以,在这种情况下,我知道x 的值,但我需要计算y 的值。
这里是 SVG 文件的来源:
<?xml version="1.0" encoding="UTF-8"?>
<svg width="1366px" height="332px" viewBox="0 0 1366 332" version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink">
<!-- Generator: Sketch 55.1 (78136) - https://sketchapp.com -->
<title>@0.5xTimeline - Deactivated</title>
<desc>Created with Sketch.</desc>
<g id="????-Design---Desktop" stroke="none" stroke-width="1" fill="none" fill-rule="evenodd">
<g id="02-About-Us" transform="translate(0.000000, -989.000000)" fill-rule="nonzero" stroke="#EFEFEF" stroke-width="11">
<g id="HISTORY" transform="translate(-28.000000, 813.000000)">
<g id="Graphic---Timeline" transform="translate(0.000000, 182.000000)">
<path d="M0,38.8855723 C99.4313478,-10.5096141 202.976477,-12.845873 310.635387,31.8767959 C472.123752,98.9607991 512.237609,231.556286 773.130376,301.214063 C1034.02314,370.871839 1355.95795,229.12379 1417,164.042295" id="Timeline---Deactivated"></path>
</g>
</g>
</g>
</g>
</svg>
【问题讨论】:
-
如果您有路径公式并且知道 x 值,您可以在循环中计算 y 值。您可以使用
getPointAtLength()方法或多或少地做同样的事情。只是这一次您不知道 x,但您知道到该点的路径的长度。您可以使用getTotalLength()获取路径的长度。一旦你有了路径的长度,你就可以循环for(let i = 0; i < n; i++){path.getPointAtLength(i*pathLength/n)}