Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
481 views
in Technique[技术] by (71.8m points)

c++ - How does the centripetal Catmull–Rom spline work?

From this site, which seems to have the most detailed information about Catmull-Rom splines, it seems that four points are needed to create the spline. However, it does not mention how the points p0 and p3 affect the values between p1 and p2.

Another question I have is how would you create continuous splines? Would it be as easy as defining the points p1, p2 to be continuous with p4, p5 by making p4 = p2 (that is, assuming we have p0, p1, p2, p3, p4, p5, p6, ..., pN).

A more general question is how would one calculate tangents on Catmull-Rom splines? Would it have to involve taking two points on the spline (say at 0.01, 0.011) and getting the tangent based on Pythagoras, given the position coordinates those input values give?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Take a look at equation 2 -- it describes how the control points affect the line. You can see points P0 and P3 go into the equation for plotting points along the curve from P1 to P2. You'll also see that the equation gives P1 when t == 0 and P2 when t == 1.

This example equation can be generalized. If you have points R0, R1, … RN then you can plot the points between RK and RK + 1 by using equation 2 with P0 = RK - 1, P1 = RK, P2 = RK + 1 and P3 = RK + 2.

You can't plot from R0 to R1 or from RN - 1 to RN unless you add extra control points to stand in for R - 1 and RN + 1. The general idea is that you can pick whatever points you want to add to the head and tail of a sequence to give yourself all the parameters to calculate the spline.

You can join two splines together by dropping one of the control points between them. Say you have R0, R1, …, RN and S0, S1, … SM they can be joined into R0, R1, …, RN - 1, S1, S2, … SM.

To compute the tangent at any point just take the derivative of equation 2.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...