从一条线的平面方程

时间:2010-01-21 20:46:33

标签: javascript 3d line plane

好的,我需要做两件事:

  1. 我需要确定方程式 一条线,给定角度,来自a 点3D空间
  2. 我需要确定方程式 垂直于的平面 那条线,是一个设定的大小,用 在它的中心的原始线。
  3. 我将需要平面方程式,在给定新线方程的情况下,我可以知道它在平面上的哪个位置相交(假设它在第一个位置相交)。

1 个答案:

答案 0 :(得分:0)

  1. 那么你在3D空间中的观点将是来自X,Y,Z原点0,0,0的3D矢量形式?
  2. 角度是相对于什么线?

    1. 叉积将为您提供垂直线。
    2.     Function CrossProduct(ByVal b As Vector3d) As Vector3d
              'cross product = (ay*bz - az*by, az*bx - ax*bz, ax*by - ay*bx)
              Dim cp As New Vector3d
              cp.x = y * b.z - z * b.y
              cp.y = z * b.x - x * b.z
              cp.z = x * b.y - y * b.x
              Return cp
          End Function
      
          Function DotProduct(ByVal OtherVector As Vector3d) As Double
              'calculate dot product of two vectors
              Return x * OtherVector.x + y * OtherVector.y + z * OtherVector.z
          End Function
      
          Public Class Ray3d
              Public Po As New Vector3d    'point of origin
              Public V As New Vector3d    'vector
          End Class
      
          Public Class Plane3d
              Public N As New Vector3d    'normal
              Public PoP As New Vector3d   'point on plane
          End Class
      
      
          Private Function IntersectionTest(ByVal R As Ray3d, ByVal P As Plane3d, ByRef ReturnPoint As Vector3d) As Boolean
      
              Dim RayDotPlaneNormal As Double = R.V.DotProduct(P.N)
      
              If RayDotPlaneNormal = 0 for 1 sided
                  Return False 'no intersection
              End If
      
              'PLANE EQUATION PoP.N = d
      
              Dim d As Double
              Dim PopVector As Vector3d = P.PoP.ToVector3d
              d = P.N.DotProduct(PopVector)
      
      
              'INTERSECTION EQUATION
              't = -(Po.N+d)/(V.N)
      
              Dim PointOriginVector As Vector3d
              PointOriginVector = R.Po.ToVector3d
      
              Dim PointOriginDotPlaneNormal As Double
              PointOriginDotPlaneNormal = P.N.DotProduct(PointOriginVector)
      
              Dim t As Double
              t = -(PointOriginDotPlaneNormal + d) / RayDotPlaneNormal
      
              ReturnPoint.x = R.Po.x + R.V.x * t
              ReturnPoint.y = R.Po.y + R.V.y * t
              ReturnPoint.z = R.Po.z + R.V.z * t
      
              Return True
      
          End Function