Esempio n. 1
0
class ShapeRegularPolygon(Shape):
    """ regular N-sided polygon """
    center = Coord2Property(default=(0.0, 0.0))
    radius = PositiveNumberProperty(default=1.0)
    n_o_sides = IntProperty(default=8, restriction=RestrictRange(lower=3))

    def __init__(self, **kwargs):
        kwargs["closed"] = True
        super(ShapeRegularPolygon, self).__init__(**kwargs)

    def define_points(self, pts):
        if self.radius == 0.0:
            pts.append(self.center)
            return pts
        angle_step = 2 * math.pi / self.n_o_sides
        for i in xrange(0, self.n_o_sides):
            pts.append(
                (self.center[0] +
                 self.radius * math.cos((i + 0.5) * angle_step + math.pi / 2),
                 self.center[1] +
                 self.radius * math.sin((i + 0.5) * angle_step + math.pi / 2)))
        return pts

    def move(self, position):
        self.center = Coord2(self.center[0] + position[0],
                             self.center[1] + position[1])
        return self

    def is_empty(self):
        return (self.radius == 0.0)
Esempio n. 2
0
class ShapePathSpike(__ShapePathBase__):
    """ simple path based on a centerline shape,but with a sharp endpoint with a given angle """
    spike_angle = AngleProperty(restriction = RestrictRange(0.0, 180.0, False, True), default = 90.0)
    

    def define_points(self, pts):
        original = self.__get_original_shape_without_straight_angles__()
        if len(original) <= 1: return
        a = original.angles_rad() 
        a2 = a * 0.5
        a1 = roll(a2, 1)

        if original.closed:
            a2[-1] = a2[0]
            a1[0] = a1[-1]
        else:
            a2[-1] = self.end_face_angle * DEG2RAD - a2[-2]
            a1[0] = self.start_face_angle * DEG2RAD - a1[1]

        a_plus = a2 + a1
        cos_a_min = cos(a2 - a1)
        offsets = column_stack((-sin(a_plus) / cos_a_min, cos(a_plus) / cos_a_min)) * (0.5 * self.path_width)

        # spikes
        if not original.closed and self.spike_angle > 0 and self.spike_angle < 180.0:
            L = 0.5 * self.path_width / tan(self.spike_angle * constants.DEG2RAD * 0.5)
            start_spike = array([[original[0][0] - cos(a[0]) * L,  original[0][1] - sin(a[0]) * L]])
            end_spike = array([[original[-1][0] + cos(a[-2]) * L,  original[-1][1] + sin(a[-2]) * L]])
        else:
            start_spike = ndarray((0, 2))
            end_spike = ndarray((0, 2))

        pts = vstack((start_spike, original.points + offsets, end_spike, flipud(original.points - offsets)))
        return pts
Esempio n. 3
0
class ShapeDodecagon(ShapeRegularPolygon):
    """ dodecagon """
    n_o_sides = IntProperty(default=12, restriction=RestrictRange(lower=3))
Esempio n. 4
0
class ShapeHexagon(ShapeRegularPolygon):
    """ hexagon """
    n_o_sides = IntProperty(default=6, restriction=RestrictRange(lower=3))