Beispiel #1
0
    def GetIntersectedDoubleline(cls, lineList):
        """
        Parameters:
            lineList: Type list of Rhino.Geometry.Line
        Returns: 
           boolean
           two intersected DoubleLine
        """

        doubleLineList = []
        if len(lineList) == 4:
            for i in range(0, 4):
                if len(doubleLineList) < 2:
                    for j in range(i + 1, 4):
                        if rs.IsVectorParallelTo(lineList[i].Direction,
                                                 lineList[j].Direction) != 0:
                            myDoubleLine = cls(lineList[i], lineList[j])
                            doubleLineList.append(myDoubleLine)
                            break
                else:
                    break
        if len(doubleLineList) == 2:
            if rs.IsVectorParallelTo(doubleLineList[0].direction,
                                     doubleLineList[1].direction) == 0:
                if doubleLineList[0].width != 0 and doubleLineList[
                        1].width != 0:
                    return (True, doubleLineList)
        return (False, None)
Beispiel #2
0
def LinearDimJoin(object_id0, object_id1):
    annotation_object0 = sc.doc.Objects.Find( object_id0 )
    dim0 = annotation_object0.Geometry
    annotation_object1 = sc.doc.Objects.Find( object_id1 )
    dim1 = annotation_object1.Geometry
    if isinstance(dim0, Rhino.Geometry.LinearDimension) and isinstance(dim1, Rhino.Geometry.LinearDimension):
        _, extensionLine01End, extensionLine02End, arrowhead01End, arrowhead02End, dimlinepoint0, _ = dim0.Get3dPoints() 
        _, extensionLine11End, extensionLine12End, arrowhead11End, arrowhead12End, dimlinepoint1, _ = dim1.Get3dPoints() 

        line0 = geo.Line(arrowhead01End, arrowhead02End)
        direct0=rs.VectorUnitize(line0.Direction)
        line1 = geo.Line(arrowhead11End, arrowhead12End)
        direct1=rs.VectorUnitize(line1.Direction)
        if rs.IsVectorParallelTo(direct0, direct1 ) != 0 :
            param0 = line0.ClosestParameter(line1.From)
            param1 = line0.ClosestParameter(line1.To)
            paramDictionary = {
                    0.0 : extensionLine01End, 
                    1.0 : extensionLine02End, 
                    param0 : extensionLine11End, 
                    param1 : extensionLine12End
                    }
            extensionLineList = []
            for key in sorted(paramDictionary.keys()):
                extensionLineList.append(paramDictionary[key])

            distance0 = line0.DistanceTo(extensionLineList[0],False)
            distance1 = line1.DistanceTo(extensionLineList[0],False)
            if distance0 > distance1: 
                rs.AddLinearDimension(dim0.Plane, extensionLineList[0], extensionLineList[len(extensionLineList)-1], dimlinepoint0 )
            else:
                rs.AddLinearDimension(dim1.Plane, extensionLineList[0], extensionLineList[len(extensionLineList)-1], dimlinepoint1 )

            rs.DeleteObject(object_id0)
            rs.DeleteObject(object_id1)
Beispiel #3
0
def findTwoParallelLines():

    gp = Rhino.Input.Custom.GetPoint()
    gp.SetCommandPrompt("find doubleline by clicking a point")
    gp.Get()
    if gp.CommandResult() != Rhino.Commands.Result.Success:
        print gp.CommandResult()
    pi = gp.Point()

    obj = gp.PointOnObject()
    if obj and isinstance(obj.Object(), Rhino.DocObjects.CurveObject):
        if isinstance(obj.Object().CurveGeometry, Rhino.Geometry.LineCurve):
            line = obj.Object().CurveGeometry.Line
            width = config.DOUBLELINEWIDTHLIMIT[1]
            region = getTwoParallelLineSelectionRegion(line.From, line.To, pi,
                                                       width)
            filter = Rhino.DocObjects.ObjectType.Curve
            objects = sc.doc.Objects.FindByCrossingWindowRegion(
                sc.doc.Views.ActiveView.MainViewport, region, True, filter)
            anotherObj = None
            minDistance = config.DOUBLELINEWIDTHLIMIT[1] + 1.0
            if objects:
                for rhobj in objects:
                    # rhobj.Select(True)
                    if isinstance(rhobj.CurveGeometry, Rhino.Geometry.LineCurve
                                  ) and rhobj.Id != obj.Object().Id:
                        anotherLine = rhobj.CurveGeometry.Line
                        if rs.IsVectorParallelTo(line.Direction,
                                                 anotherLine.Direction) != 0:
                            if anotherLine.DistanceTo(pi, False) < minDistance:
                                minDistance = anotherLine.DistanceTo(pi, False)
                                anotherObj = rhobj
            return (pi, obj.Object(), anotherObj)
Beispiel #4
0
def AddArcDir(ptStart, ptEnd, vecDir):
    vecBase = rs.PointSubtract(ptEnd, ptStart)
    if rs.VectorLength(vecBase)==0.0: return
    if rs.IsVectorParallelTo(vecBase, vecDir): return
    vecBase = rs.VectorUnitize(vecBase)
    vecDir = rs.VectorUnitize(vecDir)
    vecBisector = rs.VectorAdd(vecDir, vecBase)
    vecBisector = rs.VectorUnitize(vecBisector)
    dotProd = rs.VectorDotProduct(vecBisector, vecDir)
    midLength = (0.5*rs.Distance(ptStart, ptEnd))/dotProd
    vecBisector = rs.VectorScale(vecBisector, midLength)
    return rs.AddArc3Pt(ptStart, rs.PointAdd(ptStart, vecBisector), ptEnd)
Beispiel #5
0
    def __init__(self, line0, line1):
        # initialized by two Rhino.Geometry.Line
        self.isDoubleLine = True
        self.direction = None
        self.line0 = None
        self.line1 = None
        self.width = 0

        direction0 = rs.VectorUnitize(line0.Direction)
        self.direction = direction0
        # not parallel
        if rs.IsVectorParallelTo(direction0,
                                 rs.VectorUnitize(line1.Direction)) == 0:
            self.isDoubleLine = False
        else:
            # parallel but in oppersite direction
            if rs.IsVectorParallelTo(direction0,
                                     rs.VectorUnitize(line1.Direction)) == -1:
                line1.Flip()

            # find the closest point to line1's start point
            line0ClosePoint = line0.ClosestPoint(line1.From, False)
            vector = rs.VectorCreate(line1.From, line0ClosePoint)
            distance = rs.Distance(line1.From, line0ClosePoint)

            if distance >= config.DOUBLELINEWIDTHLIMIT[
                    0] and distance <= config.DOUBLELINEWIDTHLIMIT[1]:
                self.width = distance
                angle = rs.Angle(
                    (0, 0, 0),
                    rs.VectorRotate(vector, -rs.Angle(line0.From, line0.To)[0],
                                    (0, 0, 1)))
                if abs(angle[0] - 90) < sc.doc.ModelAbsoluteTolerance:
                    self.line0 = line1
                    self.line1 = line0
                elif abs(angle[0] + 90) < sc.doc.ModelAbsoluteTolerance:
                    self.line0 = line0
                    self.line1 = line1
Beispiel #6
0
def Cremona1(no, nomes, Linhas, countPF, dicPF):
    ptos1 = []
    dicUp = {}
    for i in range(countPF):
        if i == 0:
            Spt = dicPF[nomes[i]].PointAt(0)
            Ept = dicPF[nomes[i]].PointAt(1)
        else:
            if i == 1:
                cond1 = rs.PointCompare(dicPF[nomes[i - 1]].PointAt(0),
                                        dicPF[nomes[i]].PointAt(1), Tol)
                cond2 = rs.PointCompare(dicPF[nomes[i - 1]].PointAt(0),
                                        dicPF[nomes[i]].PointAt(0), Tol)
                if cond1 or cond2:
                    pAux3 = Spt
                    Spt = Ept
                    Ept = pAux3

            if rs.PointCompare(Ept, dicPF[nomes[i]].PointAt(1), Tol):
                ptAux1 = dicPF[nomes[i]].PointAt(1)
                ptAux2 = dicPF[nomes[i]].PointAt(0)
            else:
                ptAux1 = dicPF[nomes[i]].PointAt(0)
                ptAux2 = dicPF[nomes[i]].PointAt(1)
            Ept += (ptAux2 - ptAux1)
    F1 = rs.AddLine(Ept, Spt)
    #verificar o paralelismo entre F1 no PF e FG
    vec1 = rs.VectorCreate(rs.CurveEndPoint(Linhas[-1]),
                           rs.CurveStartPoint(Linhas[-1]))
    vec2 = rs.VectorCreate(Spt, Ept)
    if rs.IsVectorParallelTo(vec2, vec1):
        print '______Paralelismo______'
    #colovcando F1 no dicionario do PF
    dicUp[nomes[-1]] = rs.coerceline(F1)
    #-cargas e nomenclatura
    #teste de tração e compressão
    sin1 = TraComp(no, F1, rs.coerceline(Linhas[-1]), nomes[-1])
    #valores das cargas
    carga1 = rs.CurveLength(F1) * sin1 / Escala
    #teste de tensão admissivel
    cor1 = teste_elemento(nomes[-1], carga1, Linhas[-1])
    #nomenclatura do FG
    txt1 = nomes[-1] + ' = ' + str('%.2f' % carga1)
    pt1 = rs.coerceline(Linhas[-1]).PointAt(.5)
    ptos1 += [pt1, txt1, cor1]
    #nomenclatura do PF
    pt1 = rs.coerceline(F1).PointAt(.5)
    txt1 = nomes[-1]
    ptos1 += [pt1, txt1, cor1]
    return dicUp, ptos1
Beispiel #7
0
def surface_border_kinks(surface_guid):
    kinks = []
    borders = surface_borders(surface_guid)
    for curve_guid in borders:
        start_tgt = rs.CurveTangent(curve_guid,
                                    rs.CurveParameter(curve_guid, 0))
        end_tgt = rs.CurveTangent(curve_guid, rs.CurveParameter(curve_guid, 1))
        if not rs.IsCurveClosed(curve_guid) or not rs.IsVectorParallelTo(
                start_tgt, end_tgt):
            start = rs.CurveStartPoint(curve_guid)
            end = rs.CurveEndPoint(curve_guid)
            if start not in kinks:
                kinks.append(start)
            if end not in kinks:
                kinks.append(end)
    return kinks
def addArc(startPt, endPt, vecDir):
    vecBase = rs.PointSubtract(endPt, startPt)
    if rs.VectorLength(vecBase) == 0.0:
        return
    if rs.IsVectorParallelTo(vecBase, vecDir):
        return

    vecBase = rs.VectorUnitize(vecBase)
    vecDir = rs.VectorUnitize(vecDir)

    vecBisector = rs.VectorAdd(vecDir, vecBase)
    vecBisector = rs.VectorUnitize(vecBisector)

    midlength = (0.5*rs.Distance(startPt, endPt)) / (rs.VectorDotProduct(vecBisector, vecDir))

    vecBisector = rs.VectorScale(vecBisector, midlength)
    return rs.AddArc3Pt(startPt, endPt, rs.PointAdd(startPt, vecBisector))
Beispiel #9
0
def addArcDiv(ptStart, ptEnd, vecDir):
    vecBase = rs.PointSubtract(ptEnd, ptStart)
    # error handling
    if rs.VectorLength(vecBase) == 0.0: return
    if rs.IsVectorParallelTo(vecBase, vecDir): return

    vecBase = rs.VectorUnitize(
        vecBase
    )  # normalize vector == force magnitude to 1 to just compare direction
    vecDir = rs.VectorUnitize(vecDir)
    vecBisector = rs.VectorAdd(vecDir, vecBase)
    vecBisector = rs.VectorUnitize(vecBisector)

    dotProd = rs.VectorDotProduct(vecBisector, vecDir)
    midLength = (0.5 * rs.Distance(ptStart, ptEnd)) / dotProd

    vecBisector = rs.VectorScale(vecBisector, midLength)
    return rs.AddArc3Pt(ptStart, rs.PointAdd(pt.Start, vecBisector), ptEnd)
Beispiel #10
0
def automatic_constraints(mesh, surface_constraint, curve_constraints = [], point_constraints = []):
    """Defines the constraints on the vertices of the mesh on a point, a curve or a surface.
    
    Parameters
    ----------
    mesh : Mesh
        A mesh.
    surface_constraint : Rhino surface guid
        A surface to project vertices.
    curve_constraints : Rhino curve guids
        Curve features on surface to constrain vertices.
    point_constraints : Rhino point guids
        Point features on surface to constrain vertices.

    Returns
    -------
    constraints: dict
        Dictionary of constraints {vertex_key: (constraint_type, constraint_information)}.

    Raises
    ------
    -

    """

    constraints = {}

    surface_boundaries = surface_borders(surface_constraint, border_type = 0)

    # set point constraints at point feature, curve feature extremities and boundary curve corners
    constrained_points = []
    for curve_guid in surface_boundaries:
        start_tgt = rs.CurveTangent(curve_guid, rs.CurveParameter(curve_guid, 0))
        end_tgt = rs.CurveTangent(curve_guid, rs.CurveParameter(curve_guid, 1))
        # add only if not closed or closed with a kink
        if not rs.IsCurveClosed(curve_guid) or not rs.IsVectorParallelTo(start_tgt, end_tgt):
            start = geometric_key(rs.CurveStartPoint(curve_guid))
            end = geometric_key(rs.CurveEndPoint(curve_guid))
            if start not in constrained_points:
                constrained_points.append(start)
            if end not in constrained_points:
                constrained_points.append(end)

    for vkey in mesh.vertices():
        xyz = mesh.vertex_coordinates(vkey)
        geom_key = geometric_key(xyz)
        if geom_key in constrained_points:
            constraints[vkey] = ['point', xyz]

    # set boundary curve constraints
    split_vertices = [vkey for vkey, constraint in constraints.items() if constraint[0] == 'point']
    split_mesh_boundaries = mesh_boundaries(mesh, vertex_splits = split_vertices)

    # constrain a mesh boundary to a surface boundary if the two extremities of the mesh boundary are on the surface boundary
    for mesh_bdry in split_mesh_boundaries:

        if mesh_bdry[0] == mesh_bdry[-1]:
            crv_cstr = None
            for vkey in mesh_bdry:
                xyz = mesh.vertex_coordinates(vkey)
                for srf_bdry in surface_boundaries:
                    if is_point_on_curve(srf_bdry, xyz):
                        crv_cstr = srf_bdry
                        break
                if crv_cstr is not None:
                    break
            if crv_cstr is not None:
                for vkey in mesh_bdry:
                    xyz = mesh.vertex_coordinates(vkey)
                    if is_point_on_curve(crv_cstr, xyz) and vkey not in constraints:
                        constraints[vkey] = ['curve', crv_cstr]
                for i, vkey in enumerate(mesh_bdry):
                    if vkey not in constraints:
                        # find next contrained point
                        n_plus = 1
                        norm_t_plus = None
                        count = len(mesh_bdry)
                        while count > 0:
                            count -= 1
                            vkey_plus = mesh_bdry[i + n_plus - len(mesh_bdry)]
                            if vkey_plus in constraints:
                                norm_t_plus = rs.CurveNormalizedParameter(crv_cstr, rs.CurveClosestPoint(crv_cstr, mesh.vertex_coordinates(vkey_plus)))
                            else:
                                n_plus += 1
                        # find previous contrained point
                        n_minus = 1
                        norm_t_minus = None
                        count = len(mesh_bdry)
                        while count > 0:
                            count -= 1
                            vkey_minus = mesh_bdry[i - n_minus]
                            if vkey_minus in constraints:
                                norm_t_minus = rs.CurveNormalizedParameter(crv_cstr, rs.CurveClosestPoint(crv_cstr, mesh.vertex_coordinates(vkey_minus)))
                            else:
                                n_minus += 1
                        # calculate barycentric parameter and move to it
                        # dichotomy required in case of curve seam being between the two parameters
                        #print n_minus, norm_t_minus, n_plus, norm_t_plus
                        if norm_t_minus == norm_t_plus:
                            norm_t = (norm_t_plus + .5) % 1
                        elif norm_t_minus < norm_t_plus:
                            norm_t = (n_minus * norm_t_plus + n_plus * norm_t_minus) / (n_minus + n_plus)
                        else:
                            norm_t_plus += 1
                            norm_t = (n_minus * norm_t_plus + n_plus * norm_t_minus) / (n_minus + n_plus)
                        # update coordiantes
                        t = rs.CurveParameter(crv_cstr, norm_t)
                        x, y, z = rs.EvaluateCurve(crv_cstr, t)
                        attr = mesh.vertex[vkey]
                        attr['x'] = x
                        attr['y'] = y
                        attr['z'] = z
                        # store constraint
                        constraints[vkey] = ['curve', crv_cstr]
        
        else:
            for srf_bdry in surface_boundaries:
                start_xyz = mesh.vertex_coordinates(mesh_bdry[0])
                end_xyz = mesh.vertex_coordinates(mesh_bdry[-1])
                # if the mesh boundary extremities match the ones of the curve boundary...
                if is_point_on_curve(srf_bdry, start_xyz) and is_point_on_curve(srf_bdry, end_xyz):
                    # ... and if there is an intermediary mesh boundary vertex on this curve boundary (needed for two-sided boundary elements)
                    to_constrain = False
                    for vkey in mesh_bdry[1 : -1]:
                        if is_point_on_curve(srf_bdry, mesh.vertex_coordinates(vkey)):
                            to_constrain = True
                    if to_constrain:
                        crv_cstr = srf_bdry
                        for vkey in mesh_bdry:
                            xyz = mesh.vertex_coordinates(vkey)
                            if is_point_on_curve(crv_cstr, xyz) and vkey not in constraints:
                                constraints[vkey] = ['curve', crv_cstr]
                        for i, vkey in enumerate(mesh_bdry):
                            if vkey not in constraints:
                                # find next contrained point
                                n_plus = 1
                                norm_t_plus = None
                                count = len(mesh_bdry)
                                while count > 0:
                                    count -= 1
                                    vkey_plus = mesh_bdry[i + n_plus - len(mesh_bdry)]
                                    if vkey_plus in constraints:
                                        norm_t_plus = rs.CurveNormalizedParameter(crv_cstr, rs.CurveClosestPoint(crv_cstr, mesh.vertex_coordinates(vkey_plus)))
                                    else:
                                        n_plus += 1
                                # find previous contrained point
                                n_minus = 1
                                norm_t_minus = None
                                count = len(mesh_bdry)
                                while count > 0:
                                    count -= 1
                                    vkey_minus = mesh_bdry[i - n_minus]
                                    if vkey_minus in constraints:
                                        norm_t_minus = rs.CurveNormalizedParameter(crv_cstr, rs.CurveClosestPoint(crv_cstr, mesh.vertex_coordinates(vkey_minus)))
                                    else:
                                        n_minus += 1
                                # calculate barycentric parameter and move to it
                                # dichotomy required in case of curve seam being between the two parameters
                                #print n_minus, norm_t_minus, n_plus, norm_t_plus
                                if norm_t_minus == norm_t_plus:
                                    norm_t = (norm_t_plus + .5) % 1
                                elif norm_t_minus < norm_t_plus:
                                    norm_t = (n_minus * norm_t_plus + n_plus * norm_t_minus) / (n_minus + n_plus)
                                else:
                                    norm_t_plus += 1
                                    norm_t = (n_minus * norm_t_plus + n_plus * norm_t_minus) / (n_minus + n_plus)
                                # update coordiantes
                                t = rs.CurveParameter(crv_cstr, norm_t)
                                x, y, z = rs.EvaluateCurve(crv_cstr, t)
                                attr = mesh.vertex[vkey]
                                attr['x'] = x
                                attr['y'] = y
                                attr['z'] = z
                                # store constraint
                                constraints[vkey] = ['curve', crv_cstr]

    # constrain to point features
    point_constraints_keys = [geometric_key(rs.PointCoordinates(pt)) for pt in point_constraints]
    for vkey in mesh.vertices():
        xyz = mesh.vertex_coordinates(vkey)
        geom_key = geometric_key(xyz)
        if geom_key in point_constraints_keys:
            constraints[vkey] = ['point', xyz]

    # constrain to curve features
    for crv in curve_constraints:
        # extremities
        start = rs.CurveStartPoint(crv)
        start_geom_key = geometric_key(start)
        end = rs.CurveEndPoint(crv)
        end_geom_key = geometric_key(end)
        for vkey in mesh.vertices():
            xyz = mesh.vertex_coordinates(vkey)
            geom_key = geometric_key(xyz)
            if geom_key == start_geom_key:
                constraints[vkey] = ['point', xyz]
                start_key = vkey
            if geom_key == end_geom_key:
                constraints[vkey] = ['point', xyz]
                end_key = vkey
        # regular nodes
        path = [start_key]
        for nbr in mesh.vertex_neighbors(start_key):
            completed = False
            if mesh.is_vertex_on_boundary(nbr):
                continue
            path.append(nbr)
            count = len(list(mesh.vertices()))
            while count > 0:
                count -= 1
                u, v = path[-2], path[-1]
                fkey = mesh.halfedge[u][v]
                x = mesh.face_vertex_descendant(fkey, v)
                fkey = mesh.halfedge[x][v]
                w = mesh.face_vertex_descendant(fkey, v)
                path.append(w)
                if w == end_key:
                    completed = True
                    break
                elif mesh.is_vertex_on_boundary(w) or len(mesh.vertex_neighbors(w)) != 4:
                    break
            if completed:
                break
            else:
                path = [start_key]
        for vkey in path[1 : -1]:
            constraints[vkey] = ['curve', crv]

        
    # set surface constraints by default for the others
    for vkey in mesh.vertices():
        if vkey not in constraints:
            constraints[vkey] = ['surface', surface_constraint]

    # udpdate drawn mesh
    layer = 'pattern_topology'
    mesh_guid = rs.ObjectsByLayer(layer)[0]
    rs.DeleteObject(mesh_guid)
    mesh_guid = draw_mesh(mesh)
    rs.ObjectLayer(mesh_guid, layer)

    return constraints, surface_boundaries