def get_shape_intersections(shape1, shape2):
    '''Returns a generator of all intersecting points found in the
    given shapes.'''

    if not isinstance(shape1, _Shape) or not isinstance(shape2, _Shape):
        raise TypeError

    for i in range(len(shape1.points)-1):
        for j in range(len(shape2.points)-1):
            intersection = get_line_intersection(
                line(shape1.points[i], shape1.points[i+1]),
                line(shape2.points[j], shape2.points[j+1]))
            if intersection:
                yield intersection
示例#2
0
def radial_ruler(radius,
                 start_angle,
                 end_angle,
                 units,
                 min_tick_height,
                 symmetric=True):

   length = end_angle - start_angle

   result = []
   for i, unit in enumerate(units):
      ticks = int(math.ceil(length / unit))
      for t in range(ticks):
         tick_height = min_tick_height * (i + 1)
         if symmetric:
            r1, a1 =  tick_height / 2, unit * t + start_angle
            r2, a2 = -tick_height / 2, unit * t + start_angle
         else:
            r1, a1 = 0, unit * t + start_angle
            r2, a2 = -tick_height, unit * t + start_angle
         xy1 = p2c(Coordinate(r1, a1) + Coordinate(radius, 0))
         xy2 = p2c(Coordinate(r2, a2) + Coordinate(radius, 0))
         tick = line(xy1, xy2)
         result.append(tick)
   return Group(result)
示例#3
0
def radial_ruler(radius,
                 start_angle,
                 end_angle,
                 units,
                 min_tick_height,
                 symmetric=True):

    length = end_angle - start_angle

    result = []
    for i, unit in enumerate(units):
        ticks = int(math.ceil(length / unit))
        for t in range(ticks):
            tick_height = min_tick_height * (i + 1)
            if symmetric:
                r1, a1 = tick_height / 2, unit * t + start_angle
                r2, a2 = -tick_height / 2, unit * t + start_angle
            else:
                r1, a1 = 0, unit * t + start_angle
                r2, a2 = -tick_height, unit * t + start_angle
            xy1 = p2c(Coordinate(r1, a1) + Coordinate(radius, 0))
            xy2 = p2c(Coordinate(r2, a2) + Coordinate(radius, 0))
            tick = line(xy1, xy2)
            result.append(tick)
    return Group(result)
示例#4
0
def ruler(start_coord, end_coord, units, min_tick_height, symmetric=False):
    """
    A measuring ruler.

    - `units` is a list of units on which to put marks, from smaller
        to larger. e.g., (10, 20, 40).
    - `min_tick_height` is the height of the marks for the smallest units.
        The hight of the other units are multiples of this.
    - `symmetric` set to True to draw the tick lines symmetrically around
        the invisible center-line.
    """
    start_coord = Coordinate(*start_coord)
    end_coord = Coordinate(*end_coord)

    length = (end_coord - start_coord).magnitude
    angle = (end_coord - start_coord).angle

    result = []
    for i, unit in enumerate(units):
        ticks = int(math.ceil(length / unit))
        for t in range(ticks):
            tick_height = min_tick_height * (i + 1)
            if symmetric:
                x1, y1 = unit * t, tick_height / 2
                x2, y2 = unit * t, -tick_height / 2
            else:
                x1, y1 = unit * t, 0
                x2, y2 = unit * t, -tick_height
            tick = line((x1, y1), (x2, y2))
            result.append(tick)
    g = Group(result)
    rotate(g, angle, (0, 0))
    offset(g, start_coord)
    return g
示例#5
0
def ruler(start_coord, end_coord, units, min_tick_height, symmetric=False):
    '''
    A measuring ruler.

    - `units` is a list of units on which to put marks, from smaller
        to larger. e.g., (10, 20, 40).
    - `min_tick_height` is the height of the marks for the smallest units.
        The hight of the other units are multiples of this.
    - `symmetric` set to True to draw the tick lines symmetrically around
        the invisible center-line.
    '''
    start_coord = Coordinate(*start_coord)
    end_coord = Coordinate(*end_coord)

    length = (end_coord - start_coord).magnitude
    angle = (end_coord - start_coord).angle

    result = [ ]
    for i, unit in enumerate(units):
        ticks = int(math.ceil(length / unit))
        for t in range(ticks):
            tick_height = min_tick_height * (i + 1)
            if symmetric:
                x1, y1 = unit * t, tick_height / 2
                x2, y2 = unit * t, -tick_height / 2
            else:
                x1, y1 = unit * t, 0
                x2, y2 = unit * t, -tick_height
            tick = line((x1, y1), (x2, y2))
            result.append(tick)
    g = Group(result)
    rotate(g, angle, (0, 0))
    offset(g, start_coord)
    return g
示例#6
0
def grid(width, height, width_divisions,height_divisions):
    '''Rectangular grid.

    - `width` : ``int`` or ``float``, width of the rectangle.
    - `height` : ``int`` or ``float``, height of the rectangle.
    - `width_divisions` : ``int``, number of horizontal equidistant partitions.
    - `height_divisions` : ``int``, number of vertical equidistant partitions.

    '''

    ul_x = width
    bl_x = ul_x
    ur_x = ul_x + width

    ul_y = height
    ur_y = ul_y
    bl_y = ul_y - height

    x_step_size = width / width_divisions
    y_step_size = height / height_divisions

    g = Group()

    ## add horizontal lines
    for i in range(height_divisions + 1):
        step_y = y_step_size * i
        l = line((ul_x, ul_y - step_y), (ur_x, ur_y - step_y))
        g.append(l)
    ## add vertical lines

    for i in range(width_divisions + 1):
        step_x = x_step_size * i
        l = line((ul_x + step_x, ul_y), (bl_x + step_x, bl_y))
        g.append(l)

    return g
示例#7
0
文件: grid.py 项目: yratof/chiplotle
def grid(width, height, width_divisions, height_divisions):
    '''Rectangular grid.

    - `width` : ``int`` or ``float``, width of the rectangle.
    - `height` : ``int`` or ``float``, height of the rectangle.
    - `width_divisions` : ``int``, number of horizontal equidistant partitions.
    - `height_divisions` : ``int``, number of vertical equidistant partitions.

    '''

    ul_x = width
    bl_x = ul_x
    ur_x = ul_x + width

    ul_y = height
    ur_y = ul_y
    bl_y = ul_y - height

    x_step_size = width / width_divisions
    y_step_size = height / height_divisions

    g = Group()

    ## add horizontal lines
    for i in range(height_divisions + 1):
        step_y = y_step_size * i
        l = line((ul_x, ul_y - step_y), (ur_x, ur_y - step_y))
        g.append(l)
    ## add vertical lines

    for i in range(width_divisions + 1):
        step_x = x_step_size * i
        l = line((ul_x + step_x, ul_y), (bl_x + step_x, bl_y))
        g.append(l)

    return g
示例#8
0
        return None



## DEMO
if __name__ == '__main__':
    from chiplotle.geometry.shapes.line import line
    from chiplotle.geometry.core.group import Group
    from chiplotle.tools import io
    from random import randrange

    #draw a bunch of lines that do not intersect

    no_intersections = Group()

    line_1 = line([randrange(0, 4000), randrange(0, 4000)],
        [randrange(0, 4000), randrange(0, 4000)])
    no_intersections.append(line_1)

    while len(no_intersections) < 300:
        new_line = line([randrange(0, 4000), randrange(0, 4000)],
            [randrange(0, 4000), randrange(0, 4000)])

        intersection = False

        for l in no_intersections:
            if get_line_intersection(new_line, l) != None:
                intersection = True
                break

        if intersection == False:
            no_intersections.append(new_line)
示例#9
0
        x = math.cos(theta) * math.pow(math.e, (expansion_rate * theta))
        y = math.sin(theta) * math.pow(math.e, (expansion_rate * theta))

        if direction == "ccw":
            y *= -1.0

        spiral_points.append((x, y))
        theta += theta_incr

    return Path(spiral_points)


## RUN DEMO CODE

if __name__ == "__main__":
    from chiplotle.geometry.core.group import Group
    from chiplotle.geometry.shapes.line import line
    from chiplotle.tools import io

    s = spiral_logarithmic()

    # add some lines for scale
    line_right = line((0, 0), (500, 0))
    line_left = line((0, 0), (-500, 0))
    line_up = line((0, 0), (0, 500))
    line_down = line((0, 0), (0, -500))

    g = Group([s, line_right, line_left, line_up, line_down])

    io.view(g)
示例#10
0
      y = math.sin(theta) * math.pow(math.e, (expansion_rate * theta))

      if direction == "ccw":
         y *= -1.0

      spiral_points.append((x, y))
      theta += theta_incr

   return Path(spiral_points)


## RUN DEMO CODE

if __name__ == '__main__':
   from chiplotle.geometry.core.group import Group
   from chiplotle.geometry.shapes.line import line
   from chiplotle.geometry.transforms.offset import offset
   from chiplotle.tools import io

   s = spiral_logarithmic()

   #add some lines for scale
   line_right = line((0,0), (500, 0))
   line_left = line((0,0), (-500, 0))
   line_up = line((0,0), (0, 500))
   line_down = line((0,0), (0, -500))

   g = Group([s, line_right, line_left, line_up, line_down])

   io.view(g)