在3D空间中垂直于线矢量绘制点

问题描述 投票:0回答:1

An example of what I'm trying to achieve

我正在尝试在3D空间中计算与线矢量正交/垂直的点。

我想使用三角函数来做到这一点,而没有任何特定于编程语言的功能。我已经标记了C ++和Java,但是我也希望能够在其他编程语言中使用它,因此缺少特定的变量声明或函数。

目前,我正在通过在线向量周围填充一个圆来测试此功能的准确性。

我还在3D空间中旋转线矢量,以查看绘制的圆发生了什么,这是我的结果变化的地方。

某些不想要的影响包括:旋转并通过线向量的圆。圆的半径似乎随着线矢量的变化而减小,然后减小到零。

我使用this question入门,并从那时起对代码进行了一些调整。

在此方面提供的任何帮助将不胜感激-我已经花了3天的时间绘制圈子。到目前为止,这是我的代码

//Create point (px, py, pz) around line vector (v3x, v3y, v3z)
dx = line2x - line1x;
dy = line2y - line1y;
dz = line2z - line1z;

// Normalize line vector
d = sqrt(dx*dx + dy*dy + dz*dz);

// Line vector
v3x = dx/d;
v3y = dy/d;
v3z = dz/d;

// Angle and distance to plot point around line vector
angle = 123 * 180/pi; //convert to radians
radius = 4;

// Begin calculating point
s = sqrt(v3x * v3x + v3y * v3y + v3z * v3z);

// Calculate v1.
// I have been playing with these variables (v1x, v1y, v1z) to try out different configurations.
v1x = s * v3x;
v1y = s * v3y;
v1z = s * -v3z;

// Calculate v2 as cross product of v3 and v1.
v2x = v3y * v1z - v3z * v1y;
v2y = v3z * v1x - v3x * v1z;
v2z = v3x * v1y - v3y * v1x;

// Point in space around the line vector
px = line1x + (radius * (v1x * cos(angle)) + (v2x * sin(angle)));
py = line1y + (radius * (v1y * cos(angle)) + (v2y * sin(angle)));
pz = line1z + (radius * (v1z * cos(angle)) + (v2z * sin(angle)));
math geometry language-agnostic trigonometry
1个回答
0
投票

您的问题太含糊,但我想您可能真的想要。

您有穿过两点p1p2的直线,而在这条线上有一点p3。您想在p3处建立一个半径r中心圆并垂直于该线的圆。

首先找到这条线的方向向量-您已经知道了-归一化向量v3

[现在,您需要垂直于v3的任意矢量:找到v3的分量,其幅度最大,而幅度为第二。例如,abs(v3y)最大,abs(v3x)具有第二大小。交换它们,取反最大的元素,并使第三个分量为零:

p = (-v3y, v3x, 0)

此向量垂直于v3(其点积为零)

现在将其标准化

pp = p / length(p)

现在获得作为v3pp的叉积的双法线向量(我有单位长度,不需要归一化,它既垂直于v3,也垂直于pp

b = v3 x pp

现在建立所需的圈子

circlepoint(theta) = p3 + radius * pp * Cos(theta) + radius * b * Sin(theta)

还请注意,以弧度表示的角度是

angle = degrees * pi / 180
© www.soinside.com 2019 - 2024. All rights reserved.