简体   繁体   English

如何在 C# 中将四个 2D 网格点与平滑曲线连接起来,并在某个时间返回 x 和 y 位置?

[英]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.所以我试图用平滑的曲线将四个网格点与 x 和 y 值连接在一起。 Given a parameter 'time' I want to receive the x and y locations of the point on the curve at that time.给定一个参数“时间”,我想接收当时曲线上点的x 和 y 位置

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.无需在 Unity、wpf 或任何其他方式中对其进行可视化。 I don't need a draw method or anything like that.我不需要绘图方法或类似的东西。 I simply need the position value of the point in the curve.我只需要曲线中点的 position 值。

This is the sort of curve I am looking for:这是我正在寻找的曲线:

例子

Thank you in advance for helping me!预先感谢您帮助我!

Simple approach is using Catmull-Rom splines .简单的方法是使用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.请注意,参数 t 在每个点点间隔从 0 到 1 变化,因此您可以 map 您的“位置”到相应的间隔。 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.例如,如果 position 从 0 变为 1,则将其乘以 3。 Integer 结果的一部分是区间数,小数部分 - 此区间的参数 t。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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