示例#1
0
def updateSegment(objSegment, objPoint, objInterPoint):
    """
            Return a segment with trimed to the intersection point
        """
    from kernel.geoentity.segment import Segment
    from kernel.geoentity.point import Point
    from kernel.geoutil.geolib import Vector

    objProjection = objSegment.getProjection(objPoint)
    _p1, _p2 = objSegment.getEndpoints()
    if not (_p1 == objInterPoint or _p2 == objInterPoint):
        pickIntVect = Vector(objInterPoint, objProjection).mag()
        p1IntVect = Vector(objInterPoint, _p1).mag()
        if (pickIntVect == p1IntVect):
            arg = {"SEGMENT_0": _p1, "SEGMENT_1": objInterPoint}
            return Segment(arg)
        p2IntVect = Vector(objInterPoint, _p2).mag()
        if (pickIntVect == p2IntVect):
            arg = {"SEGMENT_0": objInterPoint, "SEGMENT_1": _p2}
            return Segment(arg)
    ldist = objProjection.dist(_p1)
    if ldist > objProjection.dist(_p2):
        arg = {"SEGMENT_0": _p1, "SEGMENT_1": objInterPoint}
        return Segment(arg)
    else:
        arg = {"SEGMENT_0": objInterPoint, "SEGMENT_1": _p2}
        return Segment(arg)
示例#2
0
 def getProjection(self, fromPoint):
     """
         get Projection of the point x,y in the line
     """
     p1 = self.p1
     p2 = self.p2
     v = Vector(p1, p2)
     v1 = Vector(p1, fromPoint)
     pjPoint = v.map(v1.point).point
     return p1 + pjPoint
示例#3
0
 def mirror(self, mirrorRef):
     """
         perform the mirror of the line
     """
     if not isinstance(mirrorRef, (CLine, Segment)):
         raise TypeError, "mirrorObject must be Cline Segment or a tuple of points"
     #
     startPoint, endPoint=self.getEndpoints()
     self.center.mirror(mirrorRef)
     endMirror=mirrorRef.getProjection(endPoint)
     vEnd=Vector( endPoint, endMirror)
     newStart=endMirror+vEnd.point
     self.startAngle=Vector(self.center, newStart).absAng
示例#4
0
 def updatePreview(self, position, distance, kernelCommand):
     """
         update the data at the preview item
     """
     self.prepareGeometryChange()  #qtCommand for update the scene
     for i in range(0, len(kernelCommand.value)):
         self.value[i] = self.revertToQTObject(kernelCommand.value[i])
     # Assing Command Values
     index = kernelCommand.valueIndex
     try:
         raise kernelCommand.exception[index](None)
     except (ExcPoint):
         self.value[index] = self.revertToQTObject(position)
     except (ExcLenght, ExcInt):
         if not distance or distance != None:
             self.value[index] = distance
     except (ExcAngle):
         p1 = kernelCommand.value[0]
         p2 = GeoPoint(position.x, position.y)
         ang = Vector(p1, p2).absAng
         if index == 3:
             ang = ang - self.value[2]
         self.value[index] = ang
     except:
         print "updatePreview: Exception not managed"
         return
示例#5
0
 def polygonPoint(self):
     """
         get the poligon points
     """
     if self.side <= 0:
         self.side = 6
     deltaAngle = (math.pi * 2) / self.side
     cPoint = Point(self.center.x(), self.center.y())
     vPoint = Point(self.vertex.x(), self.vertex.y())
     vertexVector = Vector(cPoint, vPoint)
     radius = vertexVector.norm
     angle = vertexVector.absAng
     pol = QtGui.QPolygonF()
     pFirst = None
     for i in range(0, int(self.side)):
         angle = deltaAngle + angle
         xsP = cPoint.x + radius * math.cos(angle) * -1.0
         ysP = cPoint.y + radius * math.sin(angle) * -1.0
         p = QtCore.QPointF(xsP, ysP)
         pol.append(p)
         if not pFirst:
             pFirst = p
     if pFirst:
         pol.append(pFirst)
     return pol
示例#6
0
 def GetTangentPoint(self, x, y, outx, outy):
     """
         Get the tangent from an axternal point
         args:
             x,y is a point near the circle
             xout,yout is a point far from the circle
         return:
             a tuple(x,y,x1,xy) that define the tangent line
     """
     firstPoint = Point(x, y)
     fromPoint = Point(outx, outy)
     twoPointDistance = self.center.Dist(fromPoint)
     if (twoPointDistance < self.radius):
         return None, None
     originPoint = Point(0.0, 0.0)
     tanMod = math.sqrt(pow(twoPointDistance, 2) - pow(self.radius, 2))
     tgAngle = math.asin(self.radius / twoPointDistance)
     #Compute the x versor
     xPoint = point.Point(1.0, 0.0)
     xVector = Vector(originPoint, xPoint)
     twoPointVector = Vector(fromPoint, self.center)
     rightAngle = twoPointVector.Ang(xVector)
     cx, cy = self.center.getCoords()
     if (outy > cy):  #stupid situation
         rightAngle = -rightAngle
     posAngle = rightAngle + tgAngle
     negAngle = rightAngle - tgAngle
     #Compute the Positive Tangent
     xCord = math.cos(posAngle)
     yCord = math.sin(posAngle)
     dirPoint = Point(xCord, yCord)  #Versor that point at the tangentPoint
     ver = Vector(originPoint, dirPoint)
     ver.Mult(tanMod)
     tangVectorPoint = ver.Point()
     posPoint = Point(tangVectorPoint + (outx, outy))
     #Compute the Negative Tangent
     xCord = math.cos(negAngle)
     yCord = math.sin(negAngle)
     dirPoint = Point(xCord, yCord)  #Versor that point at the tangentPoint
     ver = Vector(originPoint, dirPoint)
     ver.Mult(tanMod)
     tangVectorPoint = ver.Point()
     negPoint = Point(tangVectorPoint + (outx, outy))
     if firstPoint.Dist(posPoint) < firstPoint.Dist(negPoint):
         return posPoint.getCoords()
     else:
         return negPoint.getCoords()
示例#7
0
 def move(self,fromPoint, toPoint):
     """
         perform the move operation
     """
     from kernel.geoutil.geolib  import Vector
     v=Vector(fromPoint, toPoint)
     p=self+v.point
     self.__x=p.x
     self.__y=p.y
 def move(self, fromPoint, toPoint):
     """
         this method must be defined for moving operation
     """
     from kernel.geoutil.geolib import Vector
     from kernel.geoentity.point import Point
     v=Vector(fromPoint, toPoint)
     for key in self:
         if isinstance(self[key] , Point):
             self[key]+=v.point
     return v.point
示例#9
0
 def rotate(self, rotationPoint, angle):
     """
         this method must be defined for rotation
     """
     from kernel.geoutil.geolib import Vector
     from kernel.geoentity.point import Point
     v=Vector(rotationPoint,self)
     v.rotate(angle)
     p=rotationPoint+v.point
     self.__x=p.x
     self.__y=p.y
    def rotate(self, rotationPoint, angle):
        """
            this method must be defined for rotation
        """
        from kernel.geoutil.geolib import Vector
        from kernel.geoentity.point import Point

        for key in self:
            if isinstance(self[key] , Point):
                v=Vector(rotationPoint,self[key] )
                v.rotate(angle)
                self[key]=rotationPoint+v.point
示例#11
0
 def getProjection(self,fromPoint):
     """
         get Projection of the point x,y on the arc
     """
     c=self.center
     v=Vector(fromPoint,c)
     if  v.norm>self.radius:
         a=v.absAng
         pj1=Point((v.X+fromPoint.getx()-self.radius*math.cos(a)), (v.Y+fromPoint.gety()-self.radius*math.sin(a)))
         pj2=Point((v.X+fromPoint.getx()+self.radius*math.cos(a)), (v.Y+fromPoint.gety()+self.radius*math.sin(a)))
         return pj1 # ######################## adding return value for pj2
     else:
         return None
示例#12
0
 def mirror(self, mirrorRef):
     """
         perform the mirror of the line
     """
     from kernel.geoentity.cline              import CLine
     from kernel.geoentity.segment            import Segment
     from kernel.geoutil.geolib               import Vector
     if not isinstance(mirrorRef, (CLine, Segment)):
         raise TypeError, "mirrorObject must be Cline Segment or a tuple of points"
     #
     centerMirror=mirrorRef.getProjection(self)
     vCenter=Vector(self, centerMirror )
     p=centerMirror+vCenter.point
     self.__x, self.__y=p.getCoords()
示例#13
0
 def GetRadiusPointFromExt(self, x, y):
     """
         get The intersecrion point from the line(x,y,cx,cy) and the circle
     """
     _cx, _cy = self.center.getCoords()
     _r = self.radius
     centerPoint = Point(_cx, _cy)
     outPoint = Point(x, y)
     vector = Vector(outPoint, centerPoint)
     vNorm = vector.Norm()
     newNorm = abs(vNorm - _r)
     magVector = vector.Mag()
     magVector.Mult(newNorm)
     newPoint = magVector.Point()
     intPoint = Point(outPoint + newPoint)
     return intPoint.getCoords()
示例#14
0
 def getAngledVector(self, segment, point):
     """
         calculate the vector use
     """
     pi = self.intersection[0]
     p1, p2 = segment.getEndpoints()
     vs1 = Vector(pi, p1)
     vs2 = Vector(pi, p2)
     if abs(vs1.absAng - vs2.absAng) < 0.00001:
         if pi.dist(p1) > pi.dist(p2):
             return Vector(pi, p1)
         else:
             return Vector(pi, p2)
     else:
         jp = segment.getProjection(point)
         vj = Vector(pi, jp)
         if abs(vj.absAng - vs1.absAng) < 0.00001:
             return Vector(pi, p1)
         else:
             return Vector(pi, p2)
示例#15
0
 def vector(self):
     """
         Get The vector of the Segment
     """
     return Vector(self.p1, self.p2)
示例#16
0
 def vector(self):
     """
         Get The vector of the CLine
     """
     return Vector(self.p1, self.p2)
 def getAngle(self):
     """
         Calculate the angle based on the starting and ending point
     """
     v=Vector(self.value[0], self.value[1])
     return v.absAng