如何计算曲线上的点?
我正在为 wpf 编写一个自定义动画,作为一个非数学人员,我有几个问题...
如果给我两个 Point3D,From 和 To,并假设原点位于 0,0,0,我如何计算两点之间的曲线?
一旦我“绘制”了曲线并且我知道它的长度(也该怎么做?),我如何计算沿线给定距离处的 x,y,z 坐标?
谢谢!
I am writing a custom animation for wpf and as a non math guy I have a couple questions...
If I am given two Point3D's, the From and To, and assuming the origin is at 0,0,0 how do I calculate a curve between the two points?
And once I have the curve 'plotted' and I know its length (how to do that too?) how can I calculate the x,y,z coords at some given distance along the line?
Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您可能希望将曲线表示为某些其他变量的一组参数函数:
连接任意两点的曲线有无数条,因此您需要更多
决定 f(t)、g(t) 和 h(t) 应采用什么形式的信息。移动一个点
沿着曲线,您只需让 t 在 0 和 1 之间变化并计算 x、y 和 z
坐标。一种方法是定义一组您想要的控制点
曲线通过(或接近),然后用以下形式表达参数方程
样条函数。为此,您不需要知道曲线的弧长。
You'll probably want to express your curve as a set of parametric functions of some other variable:
There are an infinite number of curves connecting any two points, so you'll need more
information to decide what form f(t), g(t), and h(t) should take. To move a point
along the curve, you just let t vary between 0 and 1 and calculate the x, y, and z
coordinates. One approach is to define a set of control points that you'd like your
curve to pass through (or near), then express your parametric equations in terms of
spline functions. You won't need to know the arc length of the curve in order to do this.
所以我只是想跟进我的解决方案 - 虽然确实有无数条曲线 - 我的(措辞不好的)问题是如何在曲线上的两点之间绘制 - 最短距离,假设原点为 0, 0,0 和两个 3d 点。我所做的是将我的点从笛卡尔坐标转换为极坐标,计算给定时间的球面点,然后将该点转换回笛卡尔坐标。如果有人希望我发布实际的 C# 代码,请告诉我。
So I just wanted to follow up with my solution- while it is true there are an infinite number of curves- my (poorly worded) question was how to plot between two points on a curve- the shortest distance, assuming an origin of 0,0,0 and two 3d points. What I did was to convert my points from cartesian to polar, calculate the spherical point at a given time and then convert that point back to cartesians. If anyone wants me to post the actual C# code let me know.
要获得从 A 点到 B 点的直线向量:
可以转换为:
长度是:
要沿着向量获得一定距离的点,您需要将向量设为单位向量(长度为 1):
然后乘以您的距离:
这都是从内存中得出的,因此可能不立即编译。
CodeProject 上有A Vector Type for C#,它可以为您做很多事情。
如果您想要一条曲线,那么您需要:
a) 定义您想要的曲线类型(圆弧、样条线等)
b) 更多点(中心、控制点等)
To get a straight line vector from point A to point B:
which would translate to:
The length is:
To get a point a certain distance along the vector you need to make the vector a unit vector (length 1):
and then multiply by your distance:
This is all from memory so might not compile straight away.
There's A Vector Type for C# on CodeProject which will do a lot of this for you.
If you want a curve, then you'll need:
a) to define what type of curve you want (arc, spline, etc.)
b) more points (centres, control points etc.)