TBC Macros and Extensions

 View Only
Expand all | Collapse all

is there a more elegant way to compute the Matrix4D between two vectors - i.e. Normal and WCS

  • 1.  is there a more elegant way to compute the Matrix4D between two vectors - i.e. Normal and WCS

    Posted 17 hours ago
    Edited by Ronny Schneider 17 hours ago

    Currently I'm doing it the following way, result is correct, just wondering if there is a one-liner for it.

                                centerp = o.OriginOfUcs
                                nv = o.Normal.Clone()
                                # will only work if Normal != 0, 0, 1
                                vx = nv.Clone()
                                # rotate 90 degrees around world-Z axis and make it level with world horizon
                                vx.RotateAboutZ(math.pi/2)
                                vx.Horizon = 0
                                # don't really need vy here - do it anyway
                                # clone the axis and rotate it 90 degrees around Normal
                                vy = vx.Clone()
                                vy.Rotate(BiVector3D(nv, math.pi/2))
                                # vx, vy and Normal are now square to each other
                                
                                # compute matrix to line up UCS-X,Z with World-X,Z axis
                                rottozero = Spinor3D.ComputeRotation(vx, nv, Vector3D(1,0,0), Vector3D(0,0,1))
                                # transformation to 0, 0, 0
                                #matrixtozero = Matrix4D.BuildTransformMatrix(Vector3D(centerp), Vector3D(centerp, Point3D(0, 0, 0)), rottozero, Vector3D(1,1,1))
                                #matrixbackfromzero = Matrix4D.Inverse(matrixtozero)
                                # transformation without shift - just flatten it
                                matrixtoflat = Matrix4D.BuildTransformMatrix(Vector3D(centerp), Vector3D(0, 0, 0), rottozero, Vector3D(1,1,1))
                                matrixbackfromflat = Matrix4D.Inverse(matrixtoflat)
    

    Is there a built-in function to compute the Matrix4D between a Normal vector and World?

    I've tried,

    Plane3D.GetTransformMatrix(o.Normal)

    as shown in the ConvertToLinestring sample macro, but the result is wrong.



    ------------------------------
    Ronny Schneider
    ------------------------------



  • 2.  RE: is there a more elegant way to compute the Matrix4D between two vectors - i.e. Normal and WCS

    Posted 6 hours ago

    I'm guessing you tried the Matrix constructor (point, vector, vector)?
    In this case, I believe the Z would be the Normal and Point3D.Zero as the origin. 




    ------------------------------
    Bryce Haire
    ------------------------------