GHpython: Orient a list a Point3d

Hello Everyone,

I’am trying to Orient a list of Points using GH python.
My points are created earlier inside the script , they are not a input of the component.
I ‘am mean orient like the Orient component in GH ’ changeBasis transformation’
I tryed using rhinoscriptsyntax and RhinoCommon.

My python script below and a minimal file attached. (all data are include in the script)

Thanks for your help.
Fred



"""Forum question orient a list of Point3d
    Inputs:
        All inputs already in the code
    Output:
        points_oriented: The wanted results
    
    The following variable are internal but expose for debuging:
        list_points, original_plane , target_plane"""

__author__ = "fred"
__version__ = "2021.08.20"

import rhinoscriptsyntax as rs
import scriptcontext
import Rhino 
import Rhino.Geometry as rg

# Creating the origional points
list_points= [ rg.Point3d(-10,-10,0),
                 rg.Point3d(-8,12,0),
                 rg.Point3d(-8,7,5), ]

# creating the original and target plane 
original_plane = rg.Plane.WorldXY

target_plane_origin = rg.Point3d(20,-10,5)
target_plane_normal =  rg.Vector3d(1,1,1)
target_plane = rs.PlaneFromNormal(target_plane_origin, target_plane_normal)

# Tentative with rhinoscriptsyntax
points_oriented = []
for pt_i in list_points : 
    pt_i_oriented = rs.OrientObject( pt_i, original_plane , target_plane, flags=1 )
    points_oriented.append(pt_i_oriented)
# Do not work as rs.OrientObject expect a Guid not Point3d
    
# Tentative with Rhinoocommon
transform_i = rg.Transform.ChangeBasis(target_plane, original_plane  )
# What to do with that ?

ghpython_orient_point3d.gh (6.1 KB)

Hi,

In rhinocommon, you can do this :

import Rhino.Geometry as rg

list_points= [
    rg.Point3d(-10,-10,0),
    rg.Point3d(-8,12,0),
    rg.Point3d(-8,7,5)
]

# creating the original and target plane 
original_plane = rg.Plane.WorldXY

target_plane_origin = rg.Point3d(20,-10,5)
target_plane_normal =  rg.Vector3d(1,1,1)
target_plane = rg.Plane(target_plane_origin, target_plane_normal)
 
# cf. https://developer.rhino3d.com/api/RhinoCommon/html/M_Rhino_Geometry_Transform_PlaneToPlane.htm
xform = rg.Transform.PlaneToPlane(original_plane, target_plane)

for pt in list_points : 
    pt.Transform(xform)

This transforms your original points. If you want to keep them, you need to make a copy of the list and orient that one.

2 Likes

Just a small additional note: If your points are in a Rhino.Collections.Point3dList (i.e. not just a regular Python list, which is useful for other problems as well, such as closest point searches), you can transform them all at once using this method:

https://developer.rhino3d.com/api/RhinoCommon/html/M_Rhino_Collections_Point3dList_Transform.htm

2 Likes

Thanks both , it’s works perfect.