为线段末端的圆定义一个函数

发布于 2024-09-25 18:51:38 字数 168 浏览 1 评论 0原文

我需要一个在三个维度上返回圆上的点的函数。

该圆应该“覆盖”由点 A 和 B 及其半径定义的线段。每个帽都垂直于线段。并以端点之一为中心。

这是一个糟糕的图表

I need a function that returns points on a circle in three dimensions.

The circle should "cap" a line segment defined by points A and B and it's radius. each cap is perpendicular to the line segment. and centered at one of the endpoints.

Here is a shitty diagram

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(2

心碎无痕… 2024-10-02 18:51:38

设N为从A到B方向的单位向量,即N = (BA) / length(AB)。第一步是找到另外两个向量 X 和 Y,使得 {N, X, Y} 形成基。这意味着您还需要两个向量,以便所有对 {N, X, Y} 彼此垂直,并且它们都是单位向量。另一种思考方式是,您想要创建一个新的坐标系,其 x 轴与线段对齐。您需要找到指向 y 轴和 z 轴方向的向量。

请注意,X 和 Y 有无限多种选择。您只需要以某种方式找到两个可行的即可。

一种方法是首先找到向量 {N, W, V},其中 N 来自上方,W 和 V 是 (1,0,0)、(0,1,0) 和 (0,0 ,1).为 W 和 V 选取与 N 的最小坐标相对应的两个向量。因此,如果 N = (.31, .95, 0),则为 W 选取 (1,0,0) 和 (0,0,1) (数学极客注:这种选择 W 和 V 的方式可确保 {N,W,V} 跨越 R^3)。然后,您将Gram-Schmidt 过程应用于 {N, W, V } 得到向量 {N, X, Y} 如上所述。请注意,您需要将向量 N 作为第一个向量,以便它不会因该过程而改变。

所以现在你有两个垂直于线段并且彼此垂直的向量。这意味着围绕 A 的圆上的点是 X * cos t + Y * sin t + A,其中 0 <= t < 2 * 圆周率。这与二维圆的通常描述完全相同;它只是写在上面描述的新坐标系中。

Let N be the unit vector in the direction from A to B, i.e., N = (B-A) / length(A-B). The first step is to find two more vectors X and Y such that {N, X, Y} form a basis. That means you want two more vectors so that all pairs of {N, X, Y} are perpendicular to each other and also so that they are all unit vectors. Another way to think about this is that you want to create a new coordinate system whose x-axis lines up with the line segment. You need to find vectors pointing in the direction of the y-axis and z-axis.

Note that there are infinitely many choices for X and Y. You just need to somehow find two that work.

One way to do this is to first find vectors {N, W, V} where N is from above and W and V are two of (1,0,0), (0,1,0), and (0,0,1). Pick the two vectors for W and V that correspond to the smallest coordinates of N. So if N = (.31, .95, 0) then you pick (1,0,0) and (0,0,1) for W and V. (Math geek note: This way of picking W and V ensures that {N,W,V} spans R^3). Then you apply the Gram-Schmidt process to {N, W, V} to get vectors {N, X, Y} as above. Note that you need the vector N to be the first vector so that it doesn't get changed by the process.

So now you have two vectors that are perpendicular to the line segment and perpendicular to each other. This means the points on the circle around A are X * cos t + Y * sin t + A where 0 <= t < 2 * pi. This is exactly like the usual description of a circle in two dimensions; it is just written in the new coordinate system described above.

一向肩并 2024-10-02 18:51:38

正如 David Norman 指出的那样,关键是找到与 N 正交的两个正交单位向量 X,Y。然而,我认为计算这些的更简单方法是找到将 N 映射到 (1,0, 0),然后将 Q 下的 (0,1,0) 的图像作为 X,将 Q 下的 (0,0,1) 的图像作为 Y。虽然这听起来可能很复杂,但归结为:

s = (N [0]>0.0)? 1.0:-1.0

t = N[0] + s; f = -1.0/(s*t);

X[0] = f*N[1]*t; X[1] = 1 + f*N[1]*N[1]; X[2] = f*N[1]*N[2];

Y[0] = f*N[2]*t; Y[1] = f*N[1]*N[2]; Y[2] = 1 + f*N[2]*N[2];

As David Norman noted the crux is to find two orthogonal unit vectors X,Y that are orthogonal to N. However I think a simpler way to compute these is by finding the householder reflection Q that maps N to a multiple of (1,0,0) and then to take as X the image of (0,1,0) under Q and Y as the image of (0,0,1) under Q. While this might sound complicated it comes down to:

s = (N[0] > 0.0) ? 1.0 : -1.0

t = N[0] + s; f = -1.0/(s*t);

X[0] = f*N[1]*t; X[1] = 1 + f*N[1]*N[1]; X[2] = f*N[1]*N[2];

Y[0] = f*N[2]*t; Y[1] = f*N[1]*N[2]; Y[2] = 1 + f*N[2]*N[2];

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