如何计算曲线上的点?

发布于 2024-09-02 09:56:30 字数 178 浏览 11 评论 0原文

我正在为 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

栀子花开つ 2024-09-09 09:56:31

您可能希望将曲线表示为某些其他变量的一组参数函数:

x = f(t)
y = g(t)
z = h(t)

where 0 <= t <= 1, and

f(0) = from.x, f(1) = to.x
g(0) = from.y, g(1) = to.y
h(0) = from.z, h(1) = to.z

连接任意两点的曲线有无数条,因此您需要更多
决定 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:

x = f(t)
y = g(t)
z = h(t)

where 0 <= t <= 1, and

f(0) = from.x, f(1) = to.x
g(0) = from.y, g(1) = to.y
h(0) = from.z, h(1) = to.z

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.

一向肩并 2024-09-09 09:56:31

所以我只是想跟进我的解决方案 - 虽然确实有无数条曲线 - 我的(措辞不好的)问题是如何在曲线上的两点之间绘制 - 最短距离,假设原点为 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.

相思故 2024-09-09 09:56:30

要获得从 A 点到 B 点的直线向量:

B-A

可以转换为:

vector.x = b.x - a.x;
vector.y = b.y - a.y;
vector.z = b.z - a.z;

长度是:

length = Math.Sqrt(vector.x * vector.x +
                   vector.y * vector.y +
                   vector.z * vector.z);

要沿着向量获得一定距离的点,您需要将向量设为单位向量(长度为 1):

 vector.x = vector.x / length;
 ...

然后乘以您的距离:

 vector.x = distance * vector.x;
 ...

这都是从内存中得出的,因此可能不立即编译。

CodeProject 上有A Vector Type for C#,它可以为您做很多事情。

如果您想要一条曲线,那么您需要:

a) 定义您想要的曲线类型(圆弧、样条线等)

b) 更多点(中心、控制点等)

To get a straight line vector from point A to point B:

B - A

which would translate to:

vector.x = b.x - a.x;
vector.y = b.y - a.y;
vector.z = b.z - a.z;

The length is:

length = Math.Sqrt(vector.x * vector.x +
                   vector.y * vector.y +
                   vector.z * vector.z);

To get a point a certain distance along the vector you need to make the vector a unit vector (length 1):

 vector.x = vector.x / length;
 ...

and then multiply by your distance:

 vector.x = distance * vector.x;
 ...

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.)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文