Angle Between WorldXYPlane and Surface

Hi,

I’m looking for a way to calculate the angle between a surface and the WorldXYPlane. Does anything exist where one could either select the surface or pass it’s GUID to a function that returns the angle between it and the WorldXYPlane?

I’m looking to build a function that will lay the plane flat against the WorldXYPlane. The object will only be rotated on one axis and will not be parallel to the plane. Goal is to rotate it parallel.

Using Rhino6 with Python.

Thanks,

Eric

The main issue here is that with a planar surface, you are never sure of the orientation of the X and Y axes of the surface’s plane. So, it’s it perfectly possible to determine the angle between the plane surface’s normal and the World Z vector and rotate the surface so its normal is parallel to world Z, but I don’t know how the other axes will be oriented…

Here is a quick sketch in Python:

import rhinoscriptsyntax as rs
import scriptcontext as sc
import Rhino

def plSrf_filt(rhino_object, geometry, component_index):
    return rs.IsSurfacePlanar(geometry)

def RotatePlanarSrfToWZNormal():
    msg="Select planar surfaces to rotate"
    srf_ids=rs.GetObjects(msg,8,preselect=True,custom_filter=plSrf_filt)
    if not srf_ids: return
    
    zvec=Rhino.Geometry.Plane.WorldXY.ZAxis
    rs.EnableRedraw(False)
    for srf_id in srf_ids:
        srf=rs.coercesurface(srf_id)
        rc,plane=srf.TryGetPlane(sc.doc.ModelAbsoluteTolerance)
        if rc:
            xform=Rhino.Geometry.Transform.Rotation(plane.ZAxis,zvec,plane.Origin)
            rs.TransformObject(srf_id,xform)
RotatePlanarSrfToWZNormal()

Could you use the ChangeBasis transform? You can get the normal (and associated plane) at the centre of the surface.

This will work for me. Thank you!!!

Eric