[docs]classRhinoPoint(BaseRhinoGeometry):"""Wrapper for Rhino point objects. Attributes ---------- x (read-only) : float The X coordinate. y (read-only) : float The Y coordinate. z (read-only) : float The Z coordinate. xyz (read-only) : list The XYZ coordinates. """def__init__(self):super(RhinoPoint,self).__init__()@propertydefx(self):returnself.geometry.X@propertydefy(self):returnself.geometry.Y@propertydefz(self):returnself.geometry.Z@propertydefxyz(self):return[self.x,self.y,self.z]@classmethoddeffrom_guid(cls,guid):"""Construct a Rhino object wrapper from the GUID of an existing Rhino object. Parameters ---------- guid : str The GUID of the Rhino object. Returns ------- :class:`compas_rhino.geometry.BaseRhinoGeometry` The Rhino object wrapper. """obj=compas_rhino.find_object(guid)wrapper=cls()wrapper.guid=obj.Idwrapper.object=objwrapper.geometry=obj.Geometry.Locationreturnwrapper
[docs]@classmethoddeffrom_geometry(cls,geometry):"""Construct a point wrapper from an existing geometry object. Parameters ---------- geometry : point or :class:`Rhino.Geometry.Point3d` The input geometry. Returns ------- :class:`compas_rhino.geometry.RhinoPoint` The wrapped point. """ifnotisinstance(geometry,Rhino.Geometry.Point3d):geometry=Rhino.Geometry.Point3d(*geometry)point=cls()point.geometry=geometryreturnpoint
[docs]@classmethoddeffrom_selection(cls):"""Construct as point wrapper from a selected point object. Parameters ---------- None Returns ------- :class:`compas_rhino.geometry.RhinoPoint` The wrapped point. """guid=compas_rhino.select_point()returncls.from_guid(guid)
[docs]defto_compas(self):"""Convert the wrapper to a COMPAS point. Returns ------- :class:`compas.geometry.Point` A COMPAS point. """returnPoint(self.x,self.y,self.z)
defclosest_point(self,point,maxdist=0.0,return_param=False):"""Compute the closest point on a curve to a point in space. Parameters ---------- point : point A point location. maxdist : float, optional The maximum distance between the point on the curve and the curve. Default is ``0.0``. return_param : bool, optional Return not only the point coordinates, but also the parameter of the point on the curve. Default is ``False``. Returns ------- list The XYZ coordinates of the point. """returnself.xyz
# ==============================================================================# Main# ==============================================================================if__name__=="__main__":fromcompas.geometryimportTranslationfromcompas.geometryimportRotationpoint=RhinoPoint.from_selection()# point = RhinoPoint.from_geometry(Point3d(0, 0, 0))# point = RhinoPoint.from_geometry(Point(0, 0, 0))print(point.guid)print(point.object)print(point.geometry)print(point.type)print(point.name)print(point.xyz)p=point.to_compas()print(p)T=Translation([1.0,1.0,0.0])R=Rotation.from_axis_and_angle([0.0,0.0,1.0],0.5*3.14159)X=R*Tpoint.transform(X)p=point.to_compas()print(p)