简体   繁体   中英

How do I connect four 2D grid points with a smooth curve in C# and give the x and y location back at a certain time?

So I'm trying to connect four grid points with x and y values together with a smooth curve. Given a parameter 'time' I want to receive the x and y locations of the point on the curve at that time.

I've tried multiple options like quadratic bezier curves and such but can't seem to figure it out.

There's no need to visualize it in Unity, wpf or any other way. I don't need a draw method or anything like that. I simply need the position value of the point in the curve.

This is the sort of curve I am looking for:

例子

Thank you in advance for helping me!

Simple approach is using Catmull-Rom splines .
Example of implementation

Some more variants

Note that parameter t varies from 0 to 1 at every point-point interval, so you can map your "position" onto corresponding interval. For example, if position varies from 0 to 1, mutliply it by 3. Integer part of result is interval number, fractional part - parameter t at this interval.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM