Site Tools


Rotate Plane Parallel to World

RhinoScript

Version: Rhino 4.0
Summary: Demonstrates how to rotate a plane so its x-axis is parallel to the world using RhinoScript.

Question

I want to rotate a plane (definition, not a planar surface) about it's z-axis until it's x-axis is parallel with the world xy-plane. Is this possible?

Answer

The following sample function will do this.

Note: RhinoScript represents planes as zero-based, one-dimensional arrays containing four elements: the plane's origin (3-D point), the plane's x-axis direction (3-D vector), the plane's y-axis direction (3-D vector), and the plane's z-axis direction (3-D vector). See the RhinoScript help file for more details.

 Option Explicit
 
 '------------------------------------------------------------------------------
 ' Subroutine: XParallelPlane
 ' Purpose:    Rotate a plane about it's z-axis so that it's x-axis
               is parallel with the world xy-plane.
 ' Parameters:
 '             plane - A valid plane to rotate
 '             dir   - Direction (True = positive, False = negative)
 ' Returns:
 '             A valid plane if successful, Null otherwise.
 '------------------------------------------------------------------------------
 Function XParallelPlane(plane, dir)
 
   Dim xaxis, yaxis, zaxis
   XParallelPlane = Null 'default return value

   zaxis = Rhino.VectorUnitize(plane(3))
   If (dir = True) Then
     xaxis = Rhino.VectorUnitize(Array(zaxis(1), -zaxis(0), 0.0))
   Else
     xaxis = Rhino.VectorUnitize(Array(-zaxis(0), zaxis(1), 0.0))
   End If
 
   yaxis = Rhino.VectorCrossProduct(zaxis, xaxis)
   If IsArray(yaxis) Then
     yaxis = Rhino.VectorUnitize(yaxis)
     XParallelPlane = Rhino.PlaneFromFrame(plane(0), xaxis, yaxis)
   End If
 
 End Function
developer/scriptsamples/rotateplaneparallel.txt ยท Last modified: 2016/02/01 by sandy