.NET

Reply
Active Contributor
huaxiamengqing
Posts: 35
Registered: ‎05-23-2012
Message 11 of 11 (91 Views)

Re: Projection by a vector to a plane

05-14-2013 03:45 AM in reply to: _gile

Geat,That's What I want! I have converted it to the VB.net code under Rhino apis below!

Private Sub RunScript(ByVal P As Plane, ByVal V As Vector3d, ByRef M As Object) 
    M = ProjectionMatrix(P, V)
  End Sub 

  '<Custom additional code> 
  Public Function ProjectionMatrix(projectionPlane As Plane, projectDir As Vector3d) As Matrix
    Return ProjectionMatrix(projectionPlane.Origin, projectionPlane.Normal, projectDir)
  End Function
  Public Function ProjectionMatrix(origin As Point3d, normal As Vector3d, projectDir As Vector3d) As Matrix
    Dim scale As Double = normal.X * projectdir.X + normal.Y * projectdir.Y + normal.Z * projectdir.Z
    Dim dir As Vector3d = projectDir / scale
    Dim xVec As Vector3d = Vector3d.XAxis - normal * dir.X
    Dim yVec As Vector3d = Vector3d.YAxis - normal * dir.Y
    Dim zVec As Vector3d = Vector3d.ZAxis - normal * dir.Z
    Dim orgVec As Vector3d = New Vector3d(origin)
    Dim aa As New Matrix(4, 4)
    aa.item(0, 0) = xvec.X:  aa.item(0, 1) = xVec.Y:  aa.item(0, 2) = xVec.Z:  aa.item(0, 3) = origin.X - _
      (xVec.x * orgVec.x + xVec.y * orgVec.y + xVec.z * orgVec.z)
    aa.item(1, 0) = yvec.X:  aa.item(1, 1) = yVec.Y:  aa.item(1, 2) = yVec.Z:  aa.item(1, 3) = origin.y - _
      (yVec.x * orgVec.x + yVec.y * orgVec.y + yVec.z * orgVec.z)
    aa.item(2, 0) = zvec.X:  aa.item(2, 1) = zVec.Y:  aa.item(2, 2) = zVec.Z:  aa.item(2, 3) = origin.z - _
      (zVec.x * orgVec.x + zVec.y * orgVec.y + zVec.z * orgVec.z)
    aa.item(3, 0) = 0:  aa.item(3, 1) = 0:  aa.item(3, 2) = 0:  aa.item(3, 3) = 1
    Return aa
  End Function

 Thank you all Guys. CAD forum is Good, There are so many classical orgorithm here!

You are not logged in.

Log into access your profile, ask and answer questions, share ideas and more. Haven't signed up yet? Register

Announcements
Are you familiar with the Autodesk Expert Elites? The Expert Elite program is made up of customers that help other customers by sharing knowledge and exemplifying an engaging style of collaboration. To learn more, please visit our Expert Elite website.

Need installation help?

Start with some of our most frequented solutions to get help installing your software.

Ask the Community