views:

180

answers:

1

All right, I need to do two things:

  1. I need to determine the equation of a line, with the angle given, from a point in 3D space
  2. I need to determine the equation of a plane that is perpendicular to that line, and is a set size, with the original line in it's center.

I will need the plane's equation to be in a form where, given a new line equation, I can tell where on the plane it intersects (assuming it intersects in the first place).

A: 
  1. So your point in 3D space will be in the form of a 3D vector from the X,Y,Z origin 0,0,0 ?

The angle is relative to what line?

  1. The cross product will give you the perpendicular line.
    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

PeanutPower
Well...I can't call 3D vectors the way things stand now, I am not using a 3D engine. In fact, this is to help me build a 3D system. So I have to do everything using just math, but still in a way that Javascript can compute...that's why it's difficult.The angle is a line is really a ray that goes out from the original point, defined by x, y, z coordinates. The plane is drawn perpendicularly a certain distance along that ray, measured out from the original point.
This is VB.NET code which could be ported to JavaScript quite easily
PeanutPower
Heh heh heh, if vas ist true I need to also know how to port that. What I guess I need is to find a plane using its normal vector, knowing the point (of x y z coordinates) on the normal that also exists on the plane.