Пример #1
0
def XformShear(plane, x, y, z):
    """Returns a shear transformation matrix
    Parameters:
      plane = plane[0] is the fixed point
      x,y,z = each axis scale factor
    Returns:
      The 4x4 transformation matrix on success
    Example:
      import rhinoscriptsyntax as rs
      objects = rs.GetObjects("Select objects to shear")
      if objects:
      cplane = rs.ViewCPlane()
      xform = rs.XformShear(cplane, (1,1,0), (-1,1,0), (0,0,1))
      rs.TransformObjects(objects, xform, True)
    See Also:
      XformMirror
      XformPlanarProjection
      XformRotation
      XformScale
      XformTranslation
    """
    plane = rhutil.coerceplane(plane, True)
    x = rhutil.coerce3dvector(x, True)
    y = rhutil.coerce3dvector(y, True)
    z = rhutil.coerce3dvector(z, True)
    return Rhino.Geometry.Transform.Shear(plane,x,y,z)
Пример #2
0
def XformShear(plane, x, y, z):
    """Returns a shear transformation matrix
    Parameters:
      plane (plane): plane[0] is the fixed point
      x,y,z (number): each axis scale vector
    Returns:
      transform: The 4x4 transformation matrix on success
    Example:
      import rhinoscriptsyntax as rs
      objects = rs.GetObjects("Select objects to shear")
      if objects:
          cplane = rs.ViewCPlane()
          xform = rs.XformShear(cplane, (1,1,0), (-1,1,0), (0,0,1))
          rs.TransformObjects(objects, xform, True)
    See Also:
      XformMirror
      XformPlanarProjection
      XformRotation1
      XformRotation2
      XformRotation3
      XformRotation4
      XformScale
      XformTranslation
    """
    plane = rhutil.coerceplane(plane, True)
    x = rhutil.coerce3dvector(x, True)
    y = rhutil.coerce3dvector(y, True)
    z = rhutil.coerce3dvector(z, True)
    return Rhino.Geometry.Transform.Shear(plane, x, y, z)
Пример #3
0
def VectorAngle(vector1, vector2):
    """Returns the angle, in degrees, between two 3-D vectors
    Parameters:
      vector1 = List of 3 numbers, Point3d, or Vector3d.  The first 3-D vector.
      vector2 = List of 3 numbers, Point3d, or Vector3d.  The second 3-D vector.
    Returns:
      The angle in degrees if successfull, otherwise None
    Example:
      import rhinoscriptsyntax as rs
      s0 = rs.GetObject("Surface 0", rs.filter.surface)
      s1 = rs.GetObject("Surface 1", rs.filter.surface)
      du0 = rs.SurfaceDomain(s0, 0)
      dv0 = rs.SurfaceDomain(s0, 1)
      du1 = rs.SurfaceDomain(s1, 0)
      dv1 = rs.SurfaceDomain(s1, 1)
      n0 = rs.SurfaceNormal(s0, (du0[0], dv0[0]))
      n1 = rs.SurfaceNormal(s1, (du1[0], dv1[0]))
      print rs.VectorAngle(n0, n1)
      print rs.VectorAngle(n0, rs.VectorReverse(n1))
    See Also:
      Angle
      Angle2
    """
    vector1 = rhutil.coerce3dvector(vector1, True)
    vector2 = rhutil.coerce3dvector(vector2, True)
    vector1 = Rhino.Geometry.Vector3d(vector1.X, vector1.Y, vector1.Z)
    vector2 = Rhino.Geometry.Vector3d(vector2.X, vector2.Y, vector2.Z)
    if not vector1.Unitize() or not vector2.Unitize():
        raise ValueError("unable to unitize vector")
    dot = vector1 * vector2
    dot = rhutil.clamp(-1, 1, dot)
    radians = math.acos(dot)
    return math.degrees(radians)
Пример #4
0
def PlaneFromFrame(origin, x_axis, y_axis):
    """Construct a plane from a point, and two vectors in the plane.
    Parameters:
      origin = A 3D point identifying the origin of the plane.
      x_axis = A non-zero 3D vector in the plane that determines the X axis
               direction.
      y_axis = A non-zero 3D vector not parallel to x_axis that is used
               to determine the Y axis direction. Note, y_axis does not
               have to be perpendicular to x_axis.
    Returns:
      The plane if successful. 
    Example:
      import rhinoscriptsyntax as rs
      origin = rs.GetPoint("CPlane origin")
      if origin:
      xaxis = (1,0,0)
      yaxis = (0,0,1)
      plane = rs.PlaneFromFrame( origin, xaxis, yaxis )
      rs.ViewCPlane(None, plane)
    See Also:
      MovePlane
      PlaneFromNormal
      PlaneFromPoints
      RotatePlane
    """
    origin = rhutil.coerce3dpoint(origin, True)
    x_axis = rhutil.coerce3dvector(x_axis, True)
    y_axis = rhutil.coerce3dvector(y_axis, True)
    return Rhino.Geometry.Plane(origin, x_axis, y_axis)
Пример #5
0
def VectorAngle(vector1, vector2):
    """Returns the angle, in degrees, between two 3-D vectors
    Parameters:
      vector1 = List of 3 numbers, Point3d, or Vector3d.  The first 3-D vector.
      vector2 = List of 3 numbers, Point3d, or Vector3d.  The second 3-D vector.
    Returns:
      The angle in degrees if successfull, otherwise None
    Example:
      import rhinoscriptsyntax as rs
      s0 = rs.GetObject("Surface 0", rs.filter.surface)
      s1 = rs.GetObject("Surface 1", rs.filter.surface)
      du0 = rs.SurfaceDomain(s0, 0)
      dv0 = rs.SurfaceDomain(s0, 1)
      du1 = rs.SurfaceDomain(s1, 0)
      dv1 = rs.SurfaceDomain(s1, 1)
      n0 = rs.SurfaceNormal(s0, (du0[0], dv0[0]))
      n1 = rs.SurfaceNormal(s1, (du1[0], dv1[0]))
      print rs.VectorAngle(n0, n1)
      print rs.VectorAngle(n0, rs.VectorReverse(n1))
    See Also:
      Angle
      Angle2
    """
    vector1 = rhutil.coerce3dvector(vector1, True)
    vector2 = rhutil.coerce3dvector(vector2, True)
    vector1 = Rhino.Geometry.Vector3d(vector1.X, vector1.Y, vector1.Z)
    vector2 = Rhino.Geometry.Vector3d(vector2.X, vector2.Y, vector2.Z)
    if not vector1.Unitize() or not vector2.Unitize():
        raise ValueError("unable to unitize vector")
    dot = vector1 * vector2
    dot = rhutil.clamp(-1,1,dot)
    radians = math.acos(dot)
    return math.degrees(radians)
Пример #6
0
def PlaneFromNormal(origin, normal, xaxis=None):
    """Creates a plane from an origin point and a normal direction vector.
    Parameters:
      origin = A 3D point identifying the origin of the plane.
      normal = A 3D vector identifying the normal direction of the plane.
      xaxis[opt] = optional vector defining the plane's x-axis
    Returns:
      The plane if successful.
    Example:
      import rhinoscriptsyntax as rs
      origin = rs.GetPoint("CPlane origin")
      if origin:
      direction = rs.GetPoint("CPlane direction")
      if direction:
      normal = direction - origin
      normal = rs.VectorUnitize(normal)
      rs.ViewCPlane( None, rs.PlaneFromNormal(origin, normal) )
    See Also:
      MovePlane
      PlaneFromFrame
      PlaneFromPoints
      RotatePlane
    """
    origin = rhutil.coerce3dpoint(origin, True)
    normal = rhutil.coerce3dvector(normal, True)
    rc = Rhino.Geometry.Plane(origin, normal)
    if xaxis:
        xaxis = rhutil.coerce3dvector(xaxis, True)
        xaxis = Rhino.Geometry.Vector3d(xaxis)#prevent original xaxis parameter from being unitized too
        xaxis.Unitize()
        yaxis = Rhino.Geometry.Vector3d.CrossProduct(rc.Normal, xaxis)
        rc = Rhino.Geometry.Plane(origin, xaxis, yaxis)
    return rc
Пример #7
0
def VectorCrossProduct(vector1, vector2):
    """Calculates the cross product of two 3D vectors
    Parameters:
      vector1, vector2 = the vectors to perform cross product on
    Returns:
      the resulting vector if successful
    """
    vector1 = rhutil.coerce3dvector(vector1, True)
    vector2 = rhutil.coerce3dvector(vector2, True)
    return Rhino.Geometry.Vector3d.CrossProduct( vector1, vector2 )
Пример #8
0
def IsVectorPerpendicularTo(vector1, vector2):
    """Compares two vectors to see if they are perpendicular
    Parameters:
      vector1, vector2 = the vectors to compare
    Returns:
      True if vectors are perpendicular, otherwise False
    """
    vector1 = rhutil.coerce3dvector(vector1, True)
    vector2 = rhutil.coerce3dvector(vector2, True)
    return vector1.IsPerpendicularTo(vector2)
Пример #9
0
def VectorDotProduct(vector1, vector2):
    """Calculates the dot product of two 3D vectors
    Parameters:
      vector1, vector2 = the vectors to perform the dot product on
    Returns:
      the resulting dot product if successful
    """
    vector1 = rhutil.coerce3dvector(vector1, True)
    vector2 = rhutil.coerce3dvector(vector2, True)
    return vector1*vector2
Пример #10
0
def VectorAdd(vector1, vector2):
    """Adds two 3D vectors
    Parameters:
      vector1, vector2 = the vectors to add
    Returns:
      the resulting 3D vector if successful
    """
    vector1 = rhutil.coerce3dvector(vector1, True)
    vector2 = rhutil.coerce3dvector(vector2, True)
    return vector1+vector2
Пример #11
0
def VectorSubtract(vector1, vector2):
    """Subtracts two 3D vectors
    Parameters:
      vector1 = the vector to subtract from
      vector2 = the vector to subtract
    Returns:
      the resulting 3D vector
    """
    vector1 = rhutil.coerce3dvector(vector1, True)
    vector2 = rhutil.coerce3dvector(vector2, True)
    return vector1-vector2
Пример #12
0
def IsVectorParallelTo(vector1, vector2):
    """Compares two vectors to see if they are parallel
    Parameters:
      vector1, vector2 = the vectors to compare
    Returns:
      -1 = the vectors are anti-parallel
      0 = the vectors are not parallel
      1 = the vectors are parallel
    """
    vector1 = rhutil.coerce3dvector(vector1, True)
    vector2 = rhutil.coerce3dvector(vector2, True)
    return vector1.IsParallelTo(vector2)
Пример #13
0
def VectorAngle(vector1, vector2):
    "Returns the angle, in degrees, between two 3-D vectors"
    vector1 = rhutil.coerce3dvector(vector1, True)
    vector2 = rhutil.coerce3dvector(vector2, True)
    vector1 = Rhino.Geometry.Vector3d(vector1.X, vector1.Y, vector1.Z)
    vector2 = Rhino.Geometry.Vector3d(vector2.X, vector2.Y, vector2.Z)
    if not vector1.Unitize() or not vector2.Unitize():
        raise ValueError("unable to unitize vector")
    dot = vector1 * vector2
    dot = rhutil.clamp(-1,1,dot)
    radians = math.acos(dot)
    return math.degrees(radians)
Пример #14
0
def VectorCompare(vector1, vector2):
    """Compares two 3D vectors
    Parameters:
      vector1, vector2 = the vectors to compare
    Returns:
      -1 if vector1 is less than vector2
      0 if vector1 is equal to vector2
      1 if vector1 is greater than vector2
    """
    vector1 = rhutil.coerce3dvector(vector1, True)
    vector2 = rhutil.coerce3dvector(vector2, True)
    return vector1.CompareTo(vector2)
Пример #15
0
def XformShear(plane, x, y, z):
    """Returns a shear transformation matrix
    Parameters:
      plane = plane[0] is the fixed point
      x,y,z = each axis scale factor
    Returns:
      The 4x4 transformation matrix on success
    """
    plane = rhutil.coerceplane(plane, True)
    x = rhutil.coerce3dvector(x, True)
    y = rhutil.coerce3dvector(y, True)
    z = rhutil.coerce3dvector(z, True)
    return Rhino.Geometry.Transform.Shear(plane, x, y, z)
Пример #16
0
def XformShear(plane, x, y, z):
    """Returns a shear transformation matrix
    Parameters:
      plane = plane[0] is the fixed point
      x,y,z = each axis scale factor
    Returns:
      The 4x4 transformation matrix on success
    """
    plane = rhutil.coerceplane(plane, True)
    x = rhutil.coerce3dvector(x, True)
    y = rhutil.coerce3dvector(y, True)
    z = rhutil.coerce3dvector(z, True)
    return Rhino.Geometry.Transform.Shear(plane,x,y,z)
Пример #17
0
def VectorRotate(vector, angle_degrees, axis):
    """Rotates a 3D vector
    Parameters:
      vector = the vector to rotate
      angle_degrees = rotation angle
      axis = axis of rotation
    Returns:
      rotated vector on success
    """
    vector = rhutil.coerce3dvector(vector, True)
    axis = rhutil.coerce3dvector(axis, True)
    angle_radians = Rhino.RhinoMath.ToRadians(angle_degrees)
    rc = Rhino.Geometry.Vector3d(vector.X, vector.Y, vector.Z)
    if rc.Rotate(angle_radians, axis): return rc
Пример #18
0
def InsertBlock(block_name,
                insertion_point,
                scale=(1, 1, 1),
                angle_degrees=0,
                rotation_normal=(0, 0, 1)):
    """Inserts a block whose definition already exists in the document
    Parameters:
      block_name (str): name of an existing block definition
      insertion_point (point): insertion point for the block
      scale ({number, number, number]): x,y,z scale factors
      angle_degrees (number, optional): rotation angle in degrees
      rotation_normal (vector, optional): the axis of rotation.
    Returns:
      guid: id for the block that was added to the doc
    Example:
    See Also:
    """
    insertion_point = rhutil.coerce3dpoint(insertion_point, True)
    rotation_normal = rhutil.coerce3dvector(rotation_normal, True)
    angle_radians = math.radians(angle_degrees)
    trans = Rhino.Geometry.Transform
    move = trans.Translation(insertion_point[0], insertion_point[1],
                             insertion_point[2])
    scale = trans.Scale(Rhino.Geometry.Plane.WorldXY, scale[0], scale[1],
                        scale[2])
    rotate = trans.Rotation(angle_radians, rotation_normal,
                            Rhino.Geometry.Point3d.Origin)
    xform = move * scale * rotate
    return InsertBlock2(block_name, xform)
Пример #19
0
def RotateObjects(object_ids,
                  center_point,
                  rotation_angle,
                  axis=None,
                  copy=False):
    """Rotates multiple objects
    Parameters:
      object_ids: Identifiers of objects to rotate
      center_point: the center of rotation
      rotation_angle: in degrees
      axis[opt] = axis of rotation, If omitted, the Z axis of the active
        construction plane is used as the rotation axis
      copy[opt] = copy the object
    Returns:
      List of identifiers of the rotated objects if successful
    """
    center_point = rhutil.coerce3dpoint(center_point, True)
    if not axis:
        axis = scriptcontext.doc.Views.ActiveView.ActiveViewport.ConstructionPlane(
        ).Normal
    axis = rhutil.coerce3dvector(axis, True)
    rotation_angle = Rhino.RhinoMath.ToRadians(rotation_angle)
    xf = Rhino.Geometry.Transform.Rotation(rotation_angle, axis, center_point)
    rc = TransformObjects(object_ids, xf, copy)
    return rc
Пример #20
0
def ProjectPointToMesh(points, mesh_ids, direction):
    """Projects one or more points onto one or more meshes
    Parameters:
      points = one or more 3D points
      mesh_ids = identifiers of one or more meshes
      direction = direction vector to project the points
    Returns:
     list of projected points on success
    Example:
      import rhinoscriptsyntax as rs
      mesh = rs.GetObject("Select mesh to project onto", rs.filter.mesh)
      objects = rs.GetObjects("Select points to project", rs.filter.point)
      points = [rs.PointCoordinates(obj) for obj in objects]
      # project down...
      results = rs.ProjectPointToMesh(points, mesh, (0,0,-1))
      rs.AddPoints( results )
    See Also:
      ProjectCurveToMesh
      ProjectCurveToSurface
      ProjectPointToSurface
    """
    pts = rhutil.coerce3dpointlist(points, False)
    if pts is None:
        pts = [rhutil.coerce3dpoint(points, True)]
    direction = rhutil.coerce3dvector(direction, True)
    id = rhutil.coerceguid(mesh_ids, False)
    if id: mesh_ids = [id]
    meshes = [rhutil.coercemesh(id, True) for id in mesh_ids]
    tolerance = scriptcontext.doc.ModelAbsoluteTolerance
    rc = Rhino.Geometry.Intersect.Intersection.ProjectPointsToMeshes(meshes, pts, direction, tolerance)
    return rc
Пример #21
0
def LightDirection(object_id, direction=None):
    """Returns or changes the direction of a light object
    Parameters:
      object_id = the light object's identifier
      direction[opt] = the light's new direction
    Returns:
      if direction is not specified, the current direction
      if direction is specified, the previous direction
    Example:
      import rhinoscriptsyntax as rs
      id = rs.GetObject("Select a light", rs.filter.light)
      if id: rs.AddPoint( rs.LightDirection(id) )
    See Also:
      IsLight
      LightLocation
    """
    light = __coercelight(object_id, True)
    rc = light.Direction
    if direction:
        direction = rhutil.coerce3dvector(direction, True)
        if direction!=rc:
            light.Direction = direction
            id = rhutil.coerceguid(object_id, True)
            if not scriptcontext.doc.Lights.Modify(id, light):
                return scriptcontext.errorhandler()
            scriptcontext.doc.Views.Redraw()
    return rc
Пример #22
0
def ProjectPointToMesh(points, mesh_ids, direction):
    """Projects one or more points onto one or more meshes
    Parameters:
      points = one or more 3D points
      mesh_ids = identifiers of one or more meshes
      direction = direction vector to project the points
    Returns:
     list of projected points on success
    Example:
      import rhinoscriptsyntax as rs
      mesh = rs.GetObject("Select mesh to project onto", rs.filter.mesh)
      objects = rs.GetObjects("Select points to project", rs.filter.point)
      points = [rs.PointCoordinates(obj) for obj in objects]
      # project down...
      results = rs.ProjectPointToMesh(points, mesh, (0,0,-1))
      rs.AddPoints( results )
    See Also:
      ProjectCurveToMesh
      ProjectCurveToSurface
      ProjectPointToSurface
    """
    pts = rhutil.coerce3dpointlist(points, False)
    if pts is None:
        pts = [rhutil.coerce3dpoint(points, True)]
    direction = rhutil.coerce3dvector(direction, True)
    id = rhutil.coerceguid(mesh_ids, False)
    if id: mesh_ids = [id]
    meshes = [rhutil.coercemesh(id, True) for id in mesh_ids]
    tolerance = scriptcontext.doc.ModelAbsoluteTolerance
    rc = Rhino.Geometry.Intersect.Intersection.ProjectPointsToMeshes(
        meshes, pts, direction, tolerance)
    return rc
Пример #23
0
def LightDirection(object_id, direction=None):
    """Returns or changes the direction of a light object
    Parameters:
      object_id (guid): the light object's identifier
      direction (vector, optional): the light's new direction
    Returns:
      vector: if direction is not specified, the current direction
      vector: if direction is specified, the previous direction
    Example:
      import rhinoscriptsyntax as rs
      id = rs.GetObject("Select a light", rs.filter.light)
      if id: print( rs.LightDirection(id) )
    See Also:
      IsLight
      LightLocation
    """
    light = __coercelight(object_id, True)
    rc = light.Direction
    if direction:
        direction = rhutil.coerce3dvector(direction, True)
        if direction!=rc:
            light.Direction = direction
            id = rhutil.coerceguid(object_id, True)
            if not scriptcontext.doc.Lights.Modify(id, light):
                return scriptcontext.errorhandler()
            scriptcontext.doc.Views.Redraw()
    return rc
Пример #24
0
def XformRotation3( start_direction, end_direction, center_point ):
    """Calculate the minimal transformation that rotates start_direction to
    end_direction while fixing center_point
    Parameters:
      start_direction, end_direction = 3d vectors
      center_point = the rotation center
    Returns:
      The 4x4 transformation matrix.
      None on error.
    """
    start = rhutil.coerce3dvector(start_direction, True)
    end = rhutil.coerce3dvector(end_direction, True)
    center = rhutil.coerce3dpoint(center_point, True)
    xform = Rhino.Geometry.Transform.Rotation(start, end, center)
    if not xform.IsValid: return scriptcontext.errorhandler()
    return xform
Пример #25
0
def XformMirror(mirror_plane_point, mirror_plane_normal):
    """Creates a mirror transformation matrix
    Parameters:
      mirror_plane_point (point): point on the mirror plane
      mirror_plane_normal (vector): a 3D vector that is normal to the mirror plane
    Returns:
      transform: mirror Transform matrix
    Example:
      import rhinoscriptsyntax as rs
      objs = rs.GetObjects("Select objects to mirror")
      if objs:
          plane = rs.ViewCPlane()
          xform = rs.XformMirror(plane.Origin, plane.Normal)
          rs.TransformObjects( objs, xform, True )
    See Also:
      XformPlanarProjection
      XformRotation1
      XformRotation2
      XformRotation3
      XformRotation4
      XformScale
      XformShear
      XformTranslation
    """
    point = rhutil.coerce3dpoint(mirror_plane_point, True)
    normal = rhutil.coerce3dvector(mirror_plane_normal, True)
    return Rhino.Geometry.Transform.Mirror(point, normal)
Пример #26
0
def ProjectPointToSurface(points, surface_ids, direction):
    """Projects one or more points onto one or more surfaces or polysurfaces
    Parameters:
      points = one or more 3D points
      surface_ids = identifiers of one or more surfaces/polysurfaces
      direction = direction vector to project the points
    Returns:
     list of projected points on success
    Example:
      import rhinoscriptsyntax as rs
      surface = rs.GetObject("Select surface to project onto", rs.filter.surface)
      objects = rs.GetObjects("Select points to project", rs.filter.point)
      points = [rs.PointCoordinates(obj) for obj in objects]
      results = rs.ProjectPointToSurface(points, surface, (0,0,-1))
      rs.AddPoints(results)
    See Also:
      ProjectCurveToMesh
      ProjectCurveToSurface
      ProjectPointToMesh
    """
    pts = rhutil.coerce3dpointlist(points)
    if pts is None:
        pts = [rhutil.coerce3dpoint(points, True)]
    direction = rhutil.coerce3dvector(direction, True)
    id = rhutil.coerceguid(surface_ids, False)
    if id: surface_ids = [id]
    breps = [rhutil.coercebrep(id, True) for id in surface_ids]
    tolerance = scriptcontext.doc.ModelAbsoluteTolerance
    return Rhino.Geometry.Intersect.Intersection.ProjectPointsToBreps(breps, pts, direction, tolerance)
Пример #27
0
def PlaneFromFrame(origin, x_axis, y_axis):
    """Construct a plane from a point, and two vectors in the plane.
    Parameters:
      origin = A 3D point identifying the origin of the plane.
      x_axis = A non-zero 3D vector in the plane that determines the X axis
               direction.
      y_axis = A non-zero 3D vector not parallel to x_axis that is used
               to determine the Y axis direction. Note, y_axis does not
               have to be perpendicular to x_axis.
    Returns:
      The plane if successful. 
    """
    origin = rhutil.coerce3dpoint(origin, True)
    x_axis = rhutil.coerce3dvector(x_axis, True)
    y_axis = rhutil.coerce3dvector(y_axis, True)
    return Rhino.Geometry.Plane(origin, x_axis, y_axis)
Пример #28
0
def ProjectPointToSurface(points, surface_ids, direction):
    """Projects one or more points onto one or more surfaces or polysurfaces
    Parameters:
      points = one or more 3D points
      surface_ids = identifiers of one or more surfaces/polysurfaces
      direction = direction vector to project the points
    Returns:
     list of projected points on success
    Example:
      import rhinoscriptsyntax as rs
      surface = rs.GetObject("Select surface to project onto", rs.filter.surface)
      objects = rs.GetObjects("Select points to project", rs.filter.point)
      points = [rs.PointCoordinates(obj) for obj in objects]
      results = rs.ProjectPointToSurface(points, surface, (0,0,-1))
      rs.AddPoints(results)
    See Also:
      ProjectCurveToMesh
      ProjectCurveToSurface
      ProjectPointToMesh
    """
    pts = rhutil.coerce3dpointlist(points)
    if pts is None:
        pts = [rhutil.coerce3dpoint(points, True)]
    direction = rhutil.coerce3dvector(direction, True)
    id = rhutil.coerceguid(surface_ids, False)
    if id: surface_ids = [id]
    breps = [rhutil.coercebrep(id, True) for id in surface_ids]
    tolerance = scriptcontext.doc.ModelAbsoluteTolerance
    return Rhino.Geometry.Intersect.Intersection.ProjectPointsToBreps(
        breps, pts, direction, tolerance)
Пример #29
0
def XformRotation3(start_direction, end_direction, center_point):
    """Calculate the minimal transformation that rotates start_direction to
    end_direction while fixing center_point
    Parameters:
      start_direction, end_direction = 3d vectors
      center_point = the rotation center
    Returns:
      The 4x4 transformation matrix.
      None on error.
    """
    start = rhutil.coerce3dvector(start_direction, True)
    end = rhutil.coerce3dvector(end_direction, True)
    center = rhutil.coerce3dpoint(center_point, True)
    xform = Rhino.Geometry.Transform.Rotation(start, end, center)
    if not xform.IsValid: return scriptcontext.errorhandler()
    return xform
Пример #30
0
def PlaneFromNormal(origin, normal, xaxis=None):
    """Creates a plane from an origin point and a normal direction vector.
    Parameters:
      origin = A 3D point identifying the origin of the plane.
      normal = A 3D vector identifying the normal direction of the plane.
      xaxis[opt] = optional vector defining the plane's x-axis
    Returns:
      The plane if successful.
    """
    origin = rhutil.coerce3dpoint(origin, True)
    normal = rhutil.coerce3dvector(normal, True)
    rc = Rhino.Geometry.Plane(origin, normal)
    if xaxis:
        xaxis = rhutil.coerce3dvector(xaxis, True)
        xaxis.Unitize()
        yaxis = Rhino.Geometry.Vector3d.CrossProduct(rc.Normal, xaxis)
        rc = Rhino.Geometry.Plane(origin, xaxis, yaxis)
    return rc
Пример #31
0
def IsVectorZero(vector):
    """Verifies that a vector is zero, or tiny. The X,Y,Z elements are equal to 0.0
    Parameters:
      vector - the vector to check
    Returns:
      True if the vector is zero, otherwise False
    """
    vector = rhutil.coerce3dvector(vector, True)
    return vector.IsZero
Пример #32
0
def IsVectorTiny(vector):
    """Verifies that a vector is very short. The X,Y,Z elements are <= 1.0e-12
    Parameters:
      vector - the vector to check
    Returns:
      True if the vector is tiny, otherwise False
    """
    vector = rhutil.coerce3dvector(vector, True)
    return vector.IsTiny( 1.0e-12 )
Пример #33
0
def VectorScale(vector, scale):
    """Scales a 3-D vector
    Parameters:
      vector = the vector to scale
      scale = scale factor to apply
    Returns:
      resulting vector on success
    """
    vector = rhutil.coerce3dvector(vector, True)
    return vector*scale
Пример #34
0
def IsVectorPerpendicularTo(vector1, vector2):
    """Compares two vectors to see if they are perpendicular
    Parameters:
      vector1, vector2 = the vectors to compare
    Returns:
      True if vectors are perpendicular, otherwise False
    Example:
      import rhinoscriptsyntax as rs
      vector1 = (1,0,0)
      vector2 = (0,1,0)
      print rs.IsVectorPerpendicularTo( vector1, vector2 )
    See Also:
      IsVectorParallelTo
      IsVectorTiny
      IsVectorZero
    """
    vector1 = rhutil.coerce3dvector(vector1, True)
    vector2 = rhutil.coerce3dvector(vector2, True)
    return vector1.IsPerpendicularTo(vector2)
Пример #35
0
def VectorCrossProduct(vector1, vector2):
    """Calculates the cross product of two 3D vectors
    Parameters:
      vector1, vector2 = the vectors to perform cross product on
    Returns:
      the resulting vector if successful
    Example:
      import rhinoscriptsyntax as rs
      vector1 = (1,0,0)
      vector2 = (0,1,0)
      vector = rs.VectorCrossProduct(vector1, vector2)
      print vector
    See Also:
      VectorDotProduct
      VectorUnitize
    """
    vector1 = rhutil.coerce3dvector(vector1, True)
    vector2 = rhutil.coerce3dvector(vector2, True)
    return Rhino.Geometry.Vector3d.CrossProduct( vector1, vector2 )
Пример #36
0
def VectorDivide(vector, divide):
    """Divides a 3D vector by a value
    Parameters:
      vector = the vector to divide
      divide = a non-zero value to divide
    Returns:
      resulting vector on success
    """
    vector = rhutil.coerce3dvector(vector, True)
    return vector/divide
Пример #37
0
def VectorDotProduct(vector1, vector2):
    """Calculates the dot product of two 3D vectors
    Parameters:
      vector1, vector2 = the vectors to perform the dot product on
    Returns:
      the resulting dot product if successful
    Example:
      import rhinoscriptsyntax as rs
      vector1 = [1,0,0]
      vector2 = [0,1,0]
      dblDotProduct = rs.VectorDotProduct(vector1, vector2)
      print dblDotProduct
    See Also:
      VectorCrossProduct
      VectorUnitize
    """
    vector1 = rhutil.coerce3dvector(vector1, True)
    vector2 = rhutil.coerce3dvector(vector2, True)
    return vector1*vector2
Пример #38
0
def IsVectorPerpendicularTo(vector1, vector2):
    """Compares two vectors to see if they are perpendicular
    Parameters:
      vector1, vector2 = the vectors to compare
    Returns:
      True if vectors are perpendicular, otherwise False
    Example:
      import rhinoscriptsyntax as rs
      vector1 = (1,0,0)
      vector2 = (0,1,0)
      print rs.IsVectorPerpendicularTo( vector1, vector2 )
    See Also:
      IsVectorParallelTo
      IsVectorTiny
      IsVectorZero
    """
    vector1 = rhutil.coerce3dvector(vector1, True)
    vector2 = rhutil.coerce3dvector(vector2, True)
    return vector1.IsPerpendicularTo(vector2)
Пример #39
0
def VectorCrossProduct(vector1, vector2):
    """Calculates the cross product of two 3D vectors
    Parameters:
      vector1, vector2 = the vectors to perform cross product on
    Returns:
      the resulting vector if successful
    Example:
      import rhinoscriptsyntax as rs
      vector1 = (1,0,0)
      vector2 = (0,1,0)
      vector = rs.VectorCrossProduct(vector1, vector2)
      print vector
    See Also:
      VectorDotProduct
      VectorUnitize
    """
    vector1 = rhutil.coerce3dvector(vector1, True)
    vector2 = rhutil.coerce3dvector(vector2, True)
    return Rhino.Geometry.Vector3d.CrossProduct(vector1, vector2)
Пример #40
0
def VectorDotProduct(vector1, vector2):
    """Calculates the dot product of two 3D vectors
    Parameters:
      vector1, vector2 = the vectors to perform the dot product on
    Returns:
      the resulting dot product if successful
    Example:
      import rhinoscriptsyntax as rs
      vector1 = [1,0,0]
      vector2 = [0,1,0]
      dblDotProduct = rs.VectorDotProduct(vector1, vector2)
      print dblDotProduct
    See Also:
      VectorCrossProduct
      VectorUnitize
    """
    vector1 = rhutil.coerce3dvector(vector1, True)
    vector2 = rhutil.coerce3dvector(vector2, True)
    return vector1 * vector2
Пример #41
0
def VectorUnitize(vector):
    """Unitizes, or normalizes a 3D vector. Note, zero vectors cannot be unitized
    Parameters:
      vector = the vector to unitize
    Returns:
      unitized vector on success
      None on error
    """
    vector = rhutil.coerce3dvector(vector, True)
    rc = Rhino.Geometry.Vector3d(vector.X, vector.Y, vector.Z)
    if rc.Unitize(): return rc
Пример #42
0
def VectorTransform(vector, xform):
    """Transforms a 3D vector
    Paramters:
      vector = the vector to transform
      xform = a valid 4x4 transformation matrix
    Returns:
      transformed vector on success
    """
    vector = rhutil.coerce3dvector(vector, True)
    xform = rhutil.coercexform(xform, True)
    return xform*vector
Пример #43
0
def VectorReverse(vector):
    """Reverses the direction of a 3D vector
    Parameters:
      vector = the vector to reverse
    Returns:
      reversed vector on success
    """
    vector = rhutil.coerce3dvector(vector, True)
    rc = Rhino.Geometry.Vector3d(vector.X, vector.Y, vector.Z)
    rc.Reverse()
    return rc