Java 机器人类的贝塞尔曲线

发布于 2024-12-23 17:55:50 字数 1435 浏览 5 评论 0原文

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

云淡月浅 2024-12-30 17:55:50

根据定义,任何两个控制点都会给出平滑的贝塞尔曲线,并且起点和终点之间的直线也将是平滑曲线。您实际上可能会问两个问题之一或两个问题:

1)给定一条我希望鼠标遵循的路径,如何计算沿该路径的点?您需要该路径的参数方程。沿直线段 PQ 的点的参数方程为,

r(t) = P + tPQ

其中 P 为起点,PQ 为线段的向量形式,和 t 从 0 到 1 变化。

2) 如何找到贝塞尔曲线控制点,以便我的鼠标遵循“自然”路径? 这个是非常主观的;没有正确的答案,因为正如我所说,任何两个控制点都会产生一条连续的路径。您可以简单地选择沿路径的控制点 1/3 和 2/3,并对其坐标进行 5% 的扰动。然后,您可以使用参数贝塞尔方程来计算曲线上的点。摆弄那 5% 的数字以获得让你满意的东西。

Any two control points would give a smooth Bézier curve, by definition, and a straight line between the start and end points would also be a smooth curve. You might actually be asking one or both of two questions:

1) Given a path I want the mouse to follow, how do I compute points along the path? You need a parametric equation for the path. A parametric equation for points along a straight line segment PQ is

r(t) = P + tPQ

where P is the start point, PQ is the vector form of the line segment, and t varies from 0 to 1.

2) How do I find Bézier control points such that my mouse follows a "natural" path? This one is very subjective; there's no right answer, because as I said, any two control points will yield a continuous path. You might simply choose control points 1/3 and 2/3 along the path, perturbed by, say, 5% of their coordinates. Then you'd use the parametric Bézier equation to compute the points along the curve. Fiddle with that 5% figure to get something that pleases you.

逆夏时光 2024-12-30 17:55:50

您好,您最好从多个 4 点贝塞尔曲线中采样曲线。
要平滑连接两个 4 点贝塞尔曲线,您需要执行以下操作:

Bezier1(a0,a1,a2,a3) ... a0..a3 是前一条曲线

Bezier2(b0,b1,b2,b3 ) 的点坐标(作为向量) ) ... b0..b3 是该曲线的点坐标(作为向量)

b0 = a3 ... 确保连续性 c0

b1 = b0+(a3-a2) ... 确保连续性 c1

b2 =未知

的鼠标位置

b3 =第一条曲线

,您可以设置 a0,a1=鼠标位置所有 b3 点都是鼠标位置

所有 b2 点都是被某种比例扭曲的鼠标位置...如果您不使用比例也可以...

当您用鼠标绘制时,如果您需要更精确的鼠标路径近似值,则可以在从头开始移动一些恒定长度后添加下一条贝塞尔曲线,

因此请降低曲线段的长度常数。如果这还不够,那么您必须使用 4 点插值到 4 点贝塞尔曲线的转换,这并不那么简单。

如果您不受贝塞尔曲线的限制,请使用插值代替,那么所有点都是鼠标位置......

希望它有帮助

hi you better sample the curve from more than one 4-point bezier.
to smoothly join two 4-point beziers you need to do this:

Bezier1(a0,a1,a2,a3) ... a0..a3 are point coordinates (as vectors) of previous curve

Bezier2(b0,b1,b2,b3) ... b0..b3 are point coordinates (as vectors) of this curve

b0 = a3 ... to ensure continuity c0

b1 = b0+(a3-a2) ... to ensure continuity c1

b2 = unknown

b3 = position of mouse

for the first curve you can set a0,a1=mouse position

all b3 points are mouse position

all b2 points are mouse position distorted by some scale ... if you use no scale its also ok ...

when you draw with mouse you can add next bezier curve after some constant length is moved from the start

if you need more exact aproximation of mouse path so lower the length constant for curve segment. If it is not enough then you must use conversion of 4 point interpolation to 4 point bezier which is not as simple.

if you are not limited by bezier use interpolation instead, then all points are mouse position ...

hope it helps

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文