将坐标从法线向量给定的平面映射到 XY 平面 [英] Mapping coordinates from plane given by normal vector to XY plane

查看:34
本文介绍了将坐标从法线向量给定的平面映射到 XY 平面的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以,我有这个算法来计算具有法向量给定平面的 3D 形状的横截面.

So, I have this algorithm to calculate cross-section of 3D shape with plane given with normal vector.

但是,我目前的问题是,横截面是一组 3D 点(都位于该给定平面上),为了显示它,我需要将此坐标映射到 XY 平面.

However, my current problem is, that the cross-section is set of 3D points (all lying on that given plane) and to display it I need to map this coordinates to XY plane.

如果平面法线类似于 (0,0,c),这将非常有效 - 我只是复制 x 和 y 坐标而丢弃 z.

This works perfect if the plane normal is something like (0,0,c) - I just copy x and y coordinates discarding z.

这是我的问题:由于我不知道如何转换任何其他平原,有人可以给我任何关于我现在应该做什么的提示吗?

And here is my question: Since I have no idea how to convert any other plain could anybody give me any hint as to what should I do now?

推荐答案

您的窗格由法线向量定义

Your pane is defined by a normal vector

n=(xn,yn,zn)

对于协调变换,我们需要 2 个基向量和一个用于窗格的零点

For coordination transformation we need 2 base vectors and a zero point for the pane

基本向量

我们选择了自然"适合 x/y 窗格的那些(见后面的边缘情况):

We chose those "naturally" fitting to the x/y pane (see later for edge case):

b1=(1,0,zb1)
b2=(0,1,zb2)

我们想要

b1 x b2 = n*c (c const 标量)

b1 x b2 = n*c (c const scalar)

确保这两个是真正的基础

to make sure these two are really bases

现在解决这个问题:

b1 x b2= (0*zb2-zb1*1,zb1*0-1*zb2,1*1-0*0) = (zb1,zb2,1)
zb1*c=xn
zb2*c=yn
1*c=zn

c=zn,
zb2=yn/c=yn/zn
zb1=xn/c=xn/zn

b1=(1,0,yn/zn)
b2=(0,1,xn/zn)

并标准化

bv1=(1,0,yn/zn)*sqrt(1+(yn/zn*yn/zn))
bv2=(0,1,yn/zn)*sqrt(1+(xn/zn*xn/zn))

边缘情况是,当 zn=0 时:在这种情况下,法向量平行于 x/y 窗格并且不存在自然基向量,在这种情况下,您必须通过审美 POV 选择基 b1 和 b2 向量并经历相同的解决过程或只是选择bv1和bv2.

An edge case is, when zn=0: In this case the normal vector is parallel to the x/y pane and no natural base vectors exist, ind this case you have to chose base b1 and b2 vectors by an esthetic POV and go through the same solution process or just chose bv1 and bv2.

零点

您提到 OQ 中的窗格没有锚点,但有必要将您的窗格与无限的平行窗格系列区分开来.

you spoke of no anchor point for your pane in the OQ, but it is necessary to differentiate your pane from the infinite family of parallel panes.

如果您的锚点是 (0,0,0),这是坐标变换的完美锚点,并且您的窗格具有

If your anchor point is (0,0,0) this is a perfect anchor point for the coordinate transformation and your pane has

x*xn+y*yn+z*zn=0,
(y0,y0,z0)=(0,0,0)

如果没有,我假设您有 (xa,ya,za) 的锚点,并且您的窗格有

If not, I assume you have an anchor point of (xa,ya,za) and your pane has

x*xn+y*yn+z*zn=d

使用 d const 标量.自然拟合将是窗格的点,即通过将原始零点法向投影到窗格上来定义:

with d const scalar. A natural fit would be the point of the pane, that is defined by normal projection of the original zero point onto the pane:

P0=(x0,y0,z0)

(x0, y0, z0) = c * (xn,yn,zn)

解决这个问题

x*xn+y*yn+z*zn=d

给予

c*xn*xn+c*yn*yn+c*zn*zn=d

c=d/(xn*xn+yn*yn+zn*zn)

因此

P0=(x0,y0,z0)=c*(xn,yn,zn)

找到了.

最终转型

是通过将窗格的每个点(即您要显示的点)表示为

is achieved by representing every point of your pane (i.e. those points you want to show) as

P0+x'*bv1+y'*bv2

x' 和 y' 是新坐标.因为我们知道 P0、bv1 和 bv2,所以这很简单.如果我们不是在边缘情况下,我们在 bv1.y 和 bv2.x 中有零,进一步减少了问题.

with x' and y' being the new coordinates. Since we know P0, bv1 and bv2 this is quite trivial. If we are not on the edge case, we have zeroes in bv1.y and bv2.x further reducing the problem.

x' 和 y' 是您想要的新坐标.

x' and y' are the new coordinates you want.

这篇关于将坐标从法线向量给定的平面映射到 XY 平面的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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