确定一个平面的角度.. [英] determine the angle of a plane..

查看:81
本文介绍了确定一个平面的角度..的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在我的directX模型中创建下面的平面的矩阵代码如下所示:



 FrameTransformMatrix {
1.0,0.0,0.0,0.0,
0.0,1.0,0.0,0.0,
0.0,0.0,1.0,0.0,
2750.0,0.000163,0.000143,1.0 ;;
}





在C#中,我可以从顶点缓冲区中的现有点创建一个平面。



 Vector3 [] vectors =  new  Vector3 [mesh.MeshParts [ 0 ] VertexBuffer.VertexCount]。 
mesh.MeshParts [ 0 ]。VertexBuffer.GetData< Vector3>(向量);
Plane plane = new Plane(vectors [mesh.MeshParts [ 0 ]。StartIndex],向量[mesh.MeshParts [ 0 ]。StartIndex + 1 ],向量[mesh.MeshParts [ 0
]。StartIndex + 2 ]);





现在,有了这些信息,在我的渲染代码的effect.World部分,我如何渲染一个对象,所有3个轴对齐并接触平面?假设要放置的对象有一个以Vector3.Zero为中心的基础。



可以使用C#和XNA中现有的Matrix函数完成任务,还是数学需要要在其他地方完成吗?

解决方案

给定给定点[p]处的平面向量[n],并且你有一个绝对原点的对象模型,而你想要在与平面对齐的点[p]处渲染对象,那么你必须找到以下转换:



  1. T 1 =通过绝对z轴(即[n]与[n]投影到绝对xy平面的投影的[n]角度,将绝对y轴围绕绝对y轴旋转绝对y轴= acos())。
  2. T 2 =将绝对xy平面绕绝对z轴旋转绝对xy平面中的[n] - 角(即角度)在从上面的[n]投影到绝对x轴的绝对xy平面中。
  3. T 3 =转换为点[p]


  4. 此转换序列将您的对象转换为平面的点[p]及其对齐的轴。

    一旦找到这些转换T 1 ,T 2 ,T 3 ,你将变换的T x 乘以如下:

    T =(T < sub> 1 T x T 2 T x T 3 T T



    (M T 是M的转置矩阵,即镜像在对角线的左上角到右下角)



    使用该T变换矩阵,您将每个对象的点相乘,从而获得在所需位置渲染的对象。

    例如v plane = T xv origin



    给定

    [n] = [ n x ,n y ,n z ,1] T

    [p ] = [p x ,p y ,p z ,1] T

    q = sqrt(n x 2 + n y 2

    r = sqrt (n x 2 + n y 2 + n z 2



    T 1 =

    < td> 0
    名词<子>ž / R, 0, q / R, 0
    0, 1, 0, 0
    -q / r, 0, n z / r,
    0, 0, 0, 1




    T 2 =

    < td> 0,
    n x / q, -n y q, 0, 0
    n y / q, ñ x / q, 0, 0
    0, 0, 1, 0
    0, 0, 1




    T 3 =

    < td> 1,
    1, 0, 0, p x
    0, 0, p y
    0, 0, 1, p z
    0, 0, 0, 1



    我将T矩阵的计算作为练习;-)



    干杯

    Andi


The matrix code in my directX model from which I am creating the plane below looks like this;

FrameTransformMatrix {
  1.0, 0.0, 0.0, 0.0,
  0.0, 1.0, 0.0, 0.0,
  0.0, 0.0, 1.0, 0.0,
  2750.0, 0.000163, 0.000143, 1.0;;
}



In C# I can create a plane from existing points in the vertex buffer.

Vector3[] vectors = new Vector3[mesh.MeshParts[0].VertexBuffer.VertexCount];
mesh.MeshParts[0].VertexBuffer.GetData<Vector3>(vectors);
Plane plane = new Plane(vectors[mesh.MeshParts[0].StartIndex], vectors[mesh.MeshParts[0].StartIndex + 1], vectors[mesh.MeshParts[0].StartIndex + 2]);



Now, with this information, in the effect.World portion of my render code, how would I render an object with all 3 axes aligned to and touching the plane? Assume the object to be placed has a base centered at Vector3.Zero.

Can the task be accomplished with the existing Matrix functions in C# and XNA or will the math need to be done elsewhere?

解决方案

Given the plane vector [n] at a given point [p], and you have an object model at the absolute origin, and you want to render the object at point [p] aligned with the plane, then you must find the following transformation:


  1. T1 = rotate the absolute x-z plane around the absolute y-axis by the [n]-angle in the plane through absolute z-axis (i.e. angle of [n] to the projection of [n] to the absolute x-y plane = acos()).
  2. T2 = rotate the absolute x-y plane around the absolute z-axis by the [n]-angle in the absolute x-y plane (i.e. the angle in the absolute x-y plane from the [n] projection above to the absolute x-axis).
  3. T3 = translate to point [p]


This transformation sequence transforms your object to the plane's point [p] and its aligned axes.
Once you found these transformation T1, T2, T3, you multiply the transformed Tx as follows:
T = (T1T x T2T x T3T)T

(MT is the transposed matrix of M, i.e. mirrored at the diagonal top-left to bottom-right)

With that T transformation matrix, you multiply each object's point and so get the object rendered at the desired location.
E.g. vplane = T x vorigin

Given
[n] = [nx, ny, nz, 1]T
[p] = [px, py, pz, 1]T
q = sqrt(nx2 + ny2)
r = sqrt(nx2 + ny2 + nz2)

T1 =

nz/r,0,q/r,0
0,1,0,0
-q/r,0,nz/r,0
0,0,0,1


T2 =
nx/q,-nyq,0,0
ny/q,nx/q,0,0
0,0,1,0
0,0,0,1


T3 =
1,0,0,px
0,1,0,py
0,0,1,pz
0,0,0,1


I leave the calculation of the T-matrix as exercise ;-)

Cheers
Andi


这篇关于确定一个平面的角度..的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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