Exemple #1
0
def cornerRound(vertex, quadrant, radius, clockwise=True, ptDensity=120):
    #quadrant corresponds to quadrants 1-4
    #generate a curve to replace the vertex
    ptA = vadd(vertex, rotate_2d((0, radius), quadrant * math.pi / 2))
    ptB = vadd(vertex, rotate_2d((0, radius), (quadrant + 1) * math.pi / 2))

    return clockwise > 0 and curveAB(ptA, ptB, 1,
                                     ptDensity=ptDensity) or curveAB(
                                         ptB, ptA, -1, ptDensity=ptDensity)
Exemple #2
0
def corner(vertex, quadrant, clockwise, L, ptDensity):
    #>>>>>>>> Deprecated, use utilities.cornerRound instead <<<<<<<<<<

    #quadrant corresponds to quadrants 1-4
    #generate a curve to replace the vertex
    ptA = vadd(vertex, rotate_2d((0, L), quadrant * math.pi / 2))
    ptB = vadd(vertex, rotate_2d((0, L), (quadrant + 1) * math.pi / 2))

    return clockwise > 0 and curveAB(ptA, ptB, 1, 90, ptDensity) or curveAB(
        ptB, ptA, -1, 90, ptDensity)
Exemple #3
0
 def getPos(self, vector=None, distance=None, angle=0):
     #return global position from local position based on current location and direction
     if vector is not None:
         return vadd(self.start,
                     rotate_2d(vector, math.radians(self.direction)))
     elif distance is not None:
         return vadd(
             self.start,
             rotate_2d((distance, 0), math.radians(angle + self.direction)))
     else:
         return self.start
Exemple #4
0
 def curve_point(alpha):
     alpha = radians(alpha)
     point = (cos(alpha) * self.rx,
              sin(alpha) * self.ry)
     point = rotate_2d(point, radians(self.rotation))
     x, y = vadd(self.center, point)
     return (x, y, zaxis)
Exemple #5
0
 def shiftPos(self, distance, angle=0, newDir=None):
     #move by a specified distance, set new direction
     self.updatePos(newStart=vadd(
         self.start, rotate_2d((distance, 0),
                               math.radians(self.direction))),
                    angle=angle,
                    newDir=newDir)
Exemple #6
0
 def _transform_points(self, points):
     return [
         vadd(
             self.insert,  # move to insert point
             rotate_2d(  # rotate at origin
                 point, self.rotation)) for point in points
     ]
Exemple #7
0
 def _calc_corners(self):
     points = [(0., 0.), (self.width, 0.), (self.width, self.height),
               (0., self.height)]
     align_vector = self._get_align_vector()
     self.points = [vadd(self.insert, # move to insert point
                         rotate_2d( # rotate at origin
                             vadd(point, align_vector), self.rotation))
                    for point in points]
Exemple #8
0
 def transform(points):
     for point in points:
         if self.mirrorx:
             point = (point[0], -point[1])
         if self.mirrory:
             point = (-point[0], point[1])
         point = rotate_2d(point, rotation)
         x, y = vadd(self.start, point)
         yield (x, y, zaxis)
Exemple #9
0
 def transform(points):
     for point in points:
         if self.mirrorx:
             point = (point[0], -point[1])
         if self.mirrory:
             point = (-point[0], point[1])
         point = rotate_2d(point, rotation)
         x, y = vadd(self.start, point)
         yield (x, y, zaxis)
Exemple #10
0
 def _transform_points(self, align):
     self.points = [
         vadd(
             self.insert,  # move to insert point
             rotate_2d(  # rotate at origin
                 ((point[0] + align[0]) * self.hflip,
                  (point[1] + align[1]) * self.vflip), self.rotation))
         for point in self.points
     ]
Exemple #11
0
 def _transform_points(self):
     align = self._get_align_vector()
     self.points = [
         vadd(
             self.insert,  # move to insert point
             rotate_2d(  # rotate at origin
                 vadd((point[0] * self.hflip, point[1] * self.vflip),
                      align), self.rotation)) for point in self.points
     ]
Exemple #12
0
def curveAB(a, b, clockwise, angleDeg, ptDensity):
    #>>>>>>>> Deprecated, use utilities.curveAB instead <<<<<<<<<<

    #generate a segmented curve from A to B specified by angle. Point density = #pts / revolution
    #return list of points
    angle = math.radians(angleDeg)
    segments = int(angle / (2 * math.pi) * ptDensity)
    center = vadd(
        midpoint(a, b),
        vmul_scalar(rotate_2d(vsub(b, a), -clockwise * math.pi / 2),
                    0.5 / math.tan(angle / 2)))
    points = []
    for i in range(segments + 1):
        points.append(
            vadd(center,
                 rotate_2d(vsub(a, center),
                           -clockwise * i * angle / segments)))
    return points
Exemple #13
0
 def _calc_corners(self):
     points = [(0., 0.), (self.width, 0.), (self.width, self.height),
               (0., self.height)]
     align_vector = self._get_align_vector()
     self.points = [
         vadd(
             self.insert,  # move to insert point
             rotate_2d(  # rotate at origin
                 vadd(point, align_vector), self.rotation))
         for point in points
     ]
Exemple #14
0
def curveAB(a, b, clockwise=True, angleDeg=90, ptDensity=120):
    # generate a segmented curve from A to B specified by angle. Point density = #pts / revolution
    # return list of points
    # clockwise can be boolean {1,0} or sign type {1,-1}

    if clockwise == 0:
        clockwise = -1

    angle = math.radians(angleDeg)
    segments = int(angle / (2 * math.pi) * ptDensity)
    center = vadd(
        midpoint(a, b),
        vmul_scalar(rotate_2d(vsub(b, a), -clockwise * math.pi / 2),
                    0.5 / math.tan(angle / 2)))
    points = []
    for i in range(segments + 1):
        points.append(
            vadd(center,
                 rotate_2d(vsub(a, center),
                           -clockwise * i * angle / segments)))
    return points
Exemple #15
0
 def getLastGlobalPos(self, pos=(0, 0)):
     #return local position from global position based on previous location and direction
     localPos = vsub(pos, self.last)
     return rotate_2d(localPos, -math.radians(self.last_direction))
Exemple #16
0
 def getGlobalPos(self, pos=(0, 0)):
     #return local position from global position based on current location and direction
     localPos = vsub(pos, self.start)
     return rotate_2d(localPos, -math.radians(self.direction))
Exemple #17
0
 def curve_point(alpha):
     alpha = radians(alpha)
     point = (cos(alpha) * self.rx, sin(alpha) * self.ry)
     point = rotate_2d(point, radians(self.rotation))
     x, y = vadd(self.center, point)
     return (x, y, zaxis)