计算Bezier样条线,从点到一个点点到、Bezier、样条线

2023-09-08 09:15:29 作者:帅气不打烊"

我有2个X,Y +旋转和我需要计算Bezier样条线(二次贝济耶的集合),其平滑地连接这2点。 (参见图)点再$ P $在一场比赛中只能缓慢旋转psents单位。因此,从A点到B,它需要很长的路。所附图片显示了一个相当夸张的弯曲的路径,但你的想法。

I have 2 points in X,Y + Rotation and I need to calculate a bezier spline (a collection of quadratic beziers) that connects these 2 points smoothly. (see pic) The point represents a unit in a game which can only rotate slowly. So to get from point A to B, it has to take a long path. The attached picture shows quite an exaggeratedly curvy path, but you get the idea.

我可以使用什么公式来计算这样的Bezier样条线?

What formulas can I use to calculate such a bezier spline?

推荐答案

刚看到,我误解你的问题。你不能用一个单一的三次埃尔米特样条的,而不是因为你有一个起点和终点两个方向(切线)?是否有任何额外的限制?

Just saw that I misunderstood your question. Couldn't you use a single cubic hermite splines instead since you have a start and end point and two directions (tangents)? Are there any additional constraints?

要计算的起始和结束切线只是使用的开始和结束的方向和他们的起点和终点(另外其他一些常数因子样0.5取决于您希望如何弯曲是路径)之间的距离扩大。

To calculate the start and end tangents just use the start and end direction and scale them with the distance between the start and end points (and additionally some other constant factor like 0.5 depending on how curvy you want the path to be).:

p0 = startpoint;
p1 = endpoint;
float scale = distance(p0, p1);
m0 = Vec2(cos(startangle), sin(startangle)) * scale;
m1 = Vec2(cos(endangle), sin(endangle)) * scale;

我使用这个系统来插在一场比赛我正在拍照的路径和它的伟大工程。

I use this system to interpolate camera paths in a game I'm working on and it works great.