Bezier curve : forcing a curve of 4 points to pass through control points in 3D space

混江龙づ霸主 提交于 2021-02-11 12:25:17

问题


I have read the thread to make this happen for 4 points but only in 2D space here .

I have implemented the answer for 3D but only for 3 control points here

I have read this post but don't understand the sudo code or the math

Can anyone simplify in java? I don't want to draw the curve as 2 segments of 3 points


回答1:


Formula for cubic Bezier curve component (say X):

X(t) = P0.X*(1-t)^3 + 3*P1.X*(1-t)^2*t + 3*P2.X*(1-t)*t^2 + P3.X*t^3

where P0 and P3 are end points, and P1 an P2 are control points.

We have four points for curve (SrcPt array in that answer), end points coincide with Bezier endpoints, and two internal points on curve should define two control points P1 an P2 of Bezier curve. To calculate, we must know - what t parameters correspond to SrcPt[1] and SrcPt[2]. Let these parameters are 1/3 and 2/3 (possible issues are in linked answers).

So substitute t=1/3 and t=2/3 into the formula above:

SrcPt[1].X = SrcPt[0].X*(1-1/3)^3 + 3*P1.X*(1-1/3)^2*1/3 + 
             3*P2.X*(1-1/3)*1/3^2 + SrcPt[3].X*1/3^3
SrcPt[2].X = SrcPt[0].X*(1-2/3)^3 + 3*P1.X*(1-2/3)^2*2/3 + 
             3*P2.X*(1-2/3)*(2/3)^2 + SrcPt[3].X*2/3)^3

and solve this system for unknown P1.X and P2.X. So we will have all needed points to describe Bezier curve. Linked answer implements the solution.

Example - how changing t values for the same internal points influences on curve:



来源:https://stackoverflow.com/questions/65410883/bezier-curve-forcing-a-curve-of-4-points-to-pass-through-control-points-in-3d

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!