好吧,我需要做两件事:
- 我需要从 3D 空间中的一个点确定具有给定角度的直线方程
- 我需要确定一个平面的方程,它垂直于该线,并且是一个设定的大小,原始线在它的中心。
我需要平面方程的形式,给定一个新的线方程,我可以知道它在平面上相交的位置(假设它首先相交)。
好吧,我需要做两件事:
我需要平面方程的形式,给定一个新的线方程,我可以知道它在平面上相交的位置(假设它首先相交)。
角度是相对于哪条线的?
函数 CrossProduct(ByVal b As Vector3d) As Vector3d
'叉积 = (ay*bz - az*by, az*bx - ax*bz, ax*by - ay*bx)
将 cp 调暗为新的 Vector3d
cp.x = y * bz - z * by
cp.y = z * bx - x * bz
cp.z = x * by - y * bx
返回cp
结束功能
函数 DotProduct(ByVal OtherVector As Vector3d) As Double
'计算两个向量的点积
返回 x * OtherVector.x + y * OtherVector.y + z * OtherVector.z
结束功能
公共课 Ray3d
公共宝作为新的 Vector3d '原点
公共 V 作为新的 Vector3d '矢量
结束类
公共类Plane3d
公共 N 作为新的 Vector3d '正常
公共 PoP 作为新的 Vector3d '点在平面上
结束类
私有函数 IntersectionTest(ByVal R As Ray3d, ByVal P As Plane3d, ByRef ReturnPoint As Vector3d) As Boolean
Dim RayDotPlaneNormal As Double = RVDotProduct(PN)
如果 RayDotPlaneNormal = 0 表示 1 面
Return False '没有交集
万一
'平面方程 PoP.N = d
Dim d As Double
将 PopVector 调暗为 Vector3d = P.PoP.ToVector3d
d = PNDotProduct(PopVector)
'交集方程
't = -(Po.N+d)/(VN)
将 PointOriginVector 暗淡为 Vector3d
PointOriginVector = R.Po.ToVector3d
Dim PointOriginDotPlaneNormal As Double
PointOriginDotPlaneNormal = PNDotProduct(PointOriginVector)
Dim t As Double
t = -(PointOriginDotPlaneNormal + d) / RayDotPlaneNormal
ReturnPoint.x = R.Po.x + RVx * t
ReturnPoint.y = R.Po.y + RVy * t
ReturnPoint.z = R.Po.z + RVz * t
返回真
结束功能