I have two surfaces, surface 1 is created with midtop at 0,0,0 and lies on the OZX plane. How do make scirpt to rotate surface 1 according to surface 2 so that the two surfaces are parallel to each other but surface 1 still maintains its position?
Hi @Enscape_Master ,
This is a possible solution.
import rhinoscriptsyntax as rs
import Rhino.Geometry as rg
import scriptcontext as sc
def rotate_to_parallel():
surface1_id = rs.GetObject("Select the first surface", rs.filter.surface)
if not surface1_id: return
surface2_id = rs.GetObject("Select the second surface", rs.filter.surface)
if not surface2_id: return
surface1 = sc.doc.Objects.Find(surface1_id).Geometry
surface2 = sc.doc.Objects.Find(surface2_id).Geometry
if not isinstance(surface1, rg.Surface) or not isinstance(surface2, rg.Surface):
print("One of the selected objects is not a surface.")
return
surface1_plane = surface1.TryGetPlane()[1]
surface2_plane = surface2.TryGetPlane()[1]
angle = rg.Vector3d.VectorAngle(surface1_plane.Normal, surface2_plane.Normal)
rotation_axis = rg.Vector3d.CrossProduct(surface1_plane.Normal, surface2_plane.Normal)
if rotation_axis.IsZero: l
print("The surfaces are already parallel")
return
rotation_axis.Unitize() # Normalize the rotation axis
rotation_transform = rg.Transform.Rotation(angle, rotation_axis, surface1_plane.Origin)
surface1.Transform(rotation_transform)
sc.doc.Objects.Replace(surface1_id, surface1)
sc.doc.Views.Redraw()
print("The first surface has been rotated to be parallel to the second surface.")
rotate_to_parallel()
Hope this helps,
Farouk
1 Like
Thank you so much