向量数学,在两个向量之间的平面上找到坐标 [英] Vector math, finding coördinates on a planar between 2 vectors

查看:26
本文介绍了向量数学,在两个向量之间的平面上找到坐标的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试沿样条线生成 3d 管.我有样条曲线的坐标(x1,y1,z1 - x2,y2,z2 - 等),您可以在黄色插图中看到.在这些点上,我需要生成圆,其顶点将在以后的体育场连接.圆需要垂直于样条的两条线段的角"以形成正确的管.请注意,为了说明目的,这些段保持较低.

I am trying to generate a 3d tube along a spline. I have the coördinates of the spline (x1,y1,z1 - x2,y2,z2 - etc) which you can see in the illustration in yellow. At those points I need to generate circles, whose vertices are to be connected at a later stadium. The circles need to be perpendicular to the 'corners' of two line segments of the spline to form a correct tube. Note that the segments are kept low for illustration purpose.

[显然我不允许发布图片,所以请在此链接查看图片]http://img191.imageshack.us/img191/6863/18720019.jpg

[apparently I'm not allowed to post images so please view the image at this link] http://img191.imageshack.us/img191/6863/18720019.jpg

我能够计算样条曲线每个点处每个环的顶点,但它们都在同一个平面上,即相同的角度.我需要根据它们的腿"(例如 A 和 B 到 C)旋转它们.

I am as far as being able to calculate the vertices of each ring at each point of the spline, but they are all on the same planar ie same angled. I need them to be rotated according to their 'legs' (which A & B are to C for instance).

我一直在思考这个问题并想到以下几点:

I've been thinking this over and thought of the following:

  • 两条线段可以看作是 2 个向量(在图 A 和 B 中)
  • 角(在插图 C 中)是需要计算顶点环的地方
  • 我需要找到所有顶点所在的平面
  • 然后我可以使用这个平面(=向量?)从中心点计算新向量,即 C
  • 并使用半径 * sin 和 cos 找到它们的 x,y,z

然而,我真的对数学部分感到困惑.我读过点积,但它返回一个标量,我不知道在这种情况下如何应用.

However, I'm really confused on the math part of this. I read about the dot product but that returns a scalar which I don't know how to apply in this case.

有人能指出我正确的方向吗?

Can someone point me into the right direction?

提供更多有关情况的信息:

[edit] To give a bit more info on the situation:

我需要构造一个浮点数缓冲区,它 - 以 3 个为一组 - 描述顶点位置,并由 OpenGL ES 连接,给定另一个带有索引的缓冲区以形成多边形.

I need to construct a buffer of floats, which -in groups of 3- describe vertex positions and will be connected by OpenGL ES, given another buffer with indices to form polygons.

为了给管子赋予形状,我首先创建了一个浮点阵列,它们 - 以 3 个为一组 - 描述了 3d 空间中的控制点.

To give shape to the tube, I first created an array of floats, which -in groups of 3- describe control points in 3d space.

然后连同段密度的变量,我将这些控制点传递给一个函数,该函数使用这些控制点创建一个 CatmullRom 样条并以另一个浮点数组的形式返回它 - 再次以 3 个为一组 - 描述catmull rom 样条的顶点.

Then along with a variable for segment density, I pass these control points to a function that uses these control points to create a CatmullRom spline and returns this in the form of another array of floats which -again in groups of 3- describe vertices of the catmull rom spline.

在这些顶点中的每一个上,我想创建一个顶点环,这些顶点的密度也可以不同(每个环的平滑度/顶点数).

On each of these vertices, I want to create a ring of vertices which also can differ in density (amount of smoothness / vertices per ring).

所有以前的顶点(控制点和描述 catmull rom 样条的顶点)都被丢弃.

All former vertices (control points and those that describe the catmull rom spline) are discarded.

只有形成管环的顶点才会被传递给 OpenGL,Op​​enGL 进而将这些顶点连接起来形成最终的管.

Only the vertices that form the tube rings will be passed to OpenGL, which in turn will connect those to form the final tube.

我能够创建 catmullrom 样条曲线,并在其顶点位置创建环,但是,它们都位于相同角度的平面上,而不是遵循样条曲线路径.

I am as far as being able to create the catmullrom spline, and create rings at the position of its vertices, however, they are all on a planars that are in the same angle, instead of following the splines path.

[/编辑]

谢谢!

推荐答案

假设你有一个参数曲线,例如:

Suppose you have a parametric curve such as:

xx[t_] := Sin[t];
yy[t_] := Cos[t];
zz[t_] := t;  

这给出了:

曲线的切向量由每个方向的导数形成.在我们的例子中

The tangent vector to our curve is formed by the derivatives in each direction. In our case

Tg[t_]:= {Cos[t], -Sin[t], 1}  

该向量的正交平面来求解隐式方程:

The orthogonal plane to that vector comes solving the implicit equation:

Tg[t].{x - xx[t], y - yy[t], z - zz[t]} == 0  

在我们的例子中是:

-t + z + Cos[t] (x - Sin[t]) - (y - Cos[t]) Sin[t] == 0  

现在我们在那个平面上找到一个圆,以曲线为中心.即:

Now we find a circle in that plane, centered at the curve. i.e:

c[{x_, y_, z_, t_}] := (x - xx[t])^2 + (y - yy[t])^2 + (z - zz[t])^2 == r^2  

解决这两个方程,你得到圆的方程:

Solving both equations, you get the equation for the circles:

哈!

编辑

通过画很多圆圈,你可能会得到一个(效率不高的)管:

And by drawing a lot of circles, you may get a (not efficient) tube:

或者使用一个好的图形 3D 库:

Or with a good Graphics 3D library:

编辑

既然你坚持:) 这里是一个计算路口圆的程序.

Since you insist :) here is a program to calculate the circle at junctions.

a = {1, 2, 3}; b = {3, 2, 1}; c = {2, 3, 4};
l1 = Line[{a, b}];
l2 = Line[{b, c}];

k = Cross[(b - a), (c - b)] + b; (*Cross Product*)
angle = -ArcCos[(a - b).(c - b)/(Norm[(a - b)] Norm[(c - b)])]/2;
q = RotationMatrix[angle, k - b].(a - b);
circle[t_] := (k - b)/Norm[k - b] Sin@t + (q)/Norm[q] Cos@t + b;

Show[{Graphics3D[{
    Red, l1,
    Blue, l2,
    Black, Line[{b, k}],
    Green, Line[{b, q + b}]}, Axes -> True],
  ParametricPlot3D[circle[t], {t, 0, 2 Pi}]}]

编辑

这里有通过这种方法构建的网格.它不漂亮,恕我直言:

Here you have the mesh constructed by this method. It is not pretty, IMHO:

这篇关于向量数学,在两个向量之间的平面上找到坐标的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆