在 C/C++ 中使用 GSL 将多边形投影到平面上

发布于 2024-09-12 12:43:49 字数 369 浏览 7 评论 0原文

一般问题是将多边形投影到平面上已得到广泛解决,但我想知道是否有人可以为我的特殊情况提出一些建议。

我在 3 空间中有一个平面多边形 P,我想将其通过与单位向量 u 正交的原点投影到平面上。 P 的顶点和 u 的坐标是我拥有的唯一数据(全部基于 R^3 的标准基础)。

但是,我不仅仅想要投影坐标。我实际上想找到与 u 正交的平面的正交基,然后在这个新基中找到投影顶点的坐标。

只要基本身是正交的,基本身并不重要。所以我实际上需要在 GNU 科学库的框架内做两件事:

(1)找到与单位向量 u 正交的齐次平面的两个正交基向量。

(2) 在此基础上求P 的顶点在平面上的投影坐标。

关于如何使用 gsl 执行此操作有什么想法吗?

The general problem is projecting a polygon onto a plane is widely solved, but I was wondering if anybody could make some suggestions for my particular case.

I have a planar polygon P in 3-space and I would like to project it onto the plane through the origin that is orthogonal to the unit vector u. The vertices of P and the coordinates of u are the only data I have (all w.r.t. the standard basis of R^3).

However, I don't just want the projected coordinates. I actually would like to find an orthonormal basis of the plane orthogonal to u and to then find the coordinates of the projected vertices in this new basis.

The basis itself doesn't matter so long as it is orthonormal. So really I need to do two things within the framework of the GNU Scientific Library:

(1) Find two orthonormal basis vectors for the homogeneous plane orthogonal to the unit vector u.

(2) Find the coordinates in this basis of the projection of P's vertices onto the plane.

Any ideas on how to do this using gsl?

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

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

发布评论

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

评论(3

忆梦 2024-09-19 12:43:51

计算向量 v 和 w 以使 u,v,w 为正交基:

void    make_basis3( const double* u, double* v, double* w)
{  double   h[3];
double  d;
double  s = ( u[0] > 0.0) ? 1.0 : -1.0;
double  f = s/(s+u[0]);
h[0] = u[0]+s;  h[1] = u[1]; h[2] = u[2];
d = f*h[1]; v[0] = -d*h[0]; v[1] = 1.0-d*h[1]; v[2] = -d*h[2];
d = f*h[2]; w[0] = -d*h[0]; w[1] = -d*h[1]; w[2] = 1.0-d*h[2];
}

这里假设 u 的长度为 1。

这里发生的是前几行计算向量 h 使得
基于 h 的 Householder 矩阵(即 Q=I - 2*h*h'/h'*h,其中 ' 是转置)
将 u 映射到 (+-1,0,0),最后两行将此矩阵应用于 (0,1,0) 以获得 v
并到(0,0,1)得到w。由于 Q 是正交且对称的,因此 u,v,w 是正交基。

我认为这种方法比使用叉积更可取,因为:它更短,更高效,不易受到舍入误差的影响,并且可以推广到更高的维度。

如果 P 是一个点,则 Pv 和 Pu 是 P 通过原点投影到与 u 正交的平面上的坐标。

To compute vectors v and w so that u,v,w are an orthonormal basis:

void    make_basis3( const double* u, double* v, double* w)
{  double   h[3];
double  d;
double  s = ( u[0] > 0.0) ? 1.0 : -1.0;
double  f = s/(s+u[0]);
h[0] = u[0]+s;  h[1] = u[1]; h[2] = u[2];
d = f*h[1]; v[0] = -d*h[0]; v[1] = 1.0-d*h[1]; v[2] = -d*h[2];
d = f*h[2]; w[0] = -d*h[0]; w[1] = -d*h[1]; w[2] = 1.0-d*h[2];
}

Here u is assumed to be of length 1.

What's going on here is that the first few lines compute a vector h such that
the householder matrix based on h (ie Q=I - 2*h*h'/h'*h where ' is transpose)
maps u to (+-1,0,0) and the last two lines apply this matrix to (0,1,0) to get v
and to (0,0,1) to get w. Since Q is orthogonal and symmetric, u,v,w is an orthonormal basis.

I think this method is preferable to using cross products because: it's shorter, it's more efficient, it's less susceptible to rounding errors and it generalizes to higher dimensions.

If P is a point, P.v and P.u are coordinates of P projected onto the plane orthogonal to u, through the origin.

以可爱出名 2024-09-19 12:43:50

我没有使用过GSL,但你只需要使用点积、叉积和归一化即可得到结果。

(1) 选择任何不是 u 倍数的向量 r。令 v = ru 的归一化叉积。令 w = uv 的叉积。您的正交基向量是 vw

(2) 要将顶点a投影到该平面,它是(av) * v + ( aw) * w。 (v坐标为avw坐标为aw

为了帮助思考其工作原理,请选择 u = <1,0,0>和r = <3,0,5>开始并可视化 3 维向量。

I haven't used GSL, but you only need to use dot-product, cross-product, and normalizing to get the result.

(1) Pick any vector r that is not a multiple of u. Let v = the normalized cross-product of r and u. Let w = the cross-product of u and v. Your orthonormal basis vectors are v and w.

(2) To project a vertex a to this plane, it's (a dot v) * v + (a dot w) * w. (The v coordinate is a dot v, the w coordinate is a dot w)

To help think about how this works, choose u = <1,0,0> and r = <3,0,5> to start, and visualize the 3-d vectors.

心房的律动 2024-09-19 12:43:50

该问题缺少一项信息,即基向量之一的方向。问题说基向量必须是正交的(即,单位长度并且彼此垂直),当然垂直于 u (因为它们位于垂直于 u 的平面中),但这仍然使它们可以围绕 u 自由旋转到任何角度。

The question is missing one piece of information, namely the direction of one of the basis vectors. The question says the basis vectors must be orthonormal (i.e., unit length and perpendicular to eachother) and of course perpendicular to u (since they are in a plane perpendicular to u), but that still leaves them free to rotate around u to any angle.

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