def plot_stupid_areas(alpha=0.25):
	plt = make_plot(16, 8)
	bounds = Rectangle(39 * 22, 3000)
	plt.grid()

	plt.axis([0, 39 * 22, 0, 3000])
	plt.set_xlabel('Length / $\mathrm{mm}$')
	plt.set_ylabel('Tension / $\mathrm{N}$')

	plt.fill(
		*zip(*bounds[0]),
		color=sections.beam_graphs['1A']['color'], alpha=alpha)
	plt.annotate(
		'1A',
		xy=bounds.center(),
		textcoords='offset points',
		xytext=(0, 0),
		color=sections.beam_graphs['1A']['color'] * 0.5,
		va='bottom',
		ha='center',
		fontsize=8
	)

	plt.figure.tight_layout(pad=0)
	plt.figure.show()

	return plt
def plot_stupid_areas(alpha=0.25):
    plt = make_plot(16, 8)
    bounds = Rectangle(39 * 22, 3000)
    plt.grid()

    plt.axis([0, 39 * 22, 0, 3000])
    plt.set_xlabel('Length / $\mathrm{mm}$')
    plt.set_ylabel('Tension / $\mathrm{N}$')

    plt.fill(*zip(*bounds[0]),
             color=sections.beam_graphs['1A']['color'],
             alpha=alpha)
    plt.annotate('1A',
                 xy=bounds.center(),
                 textcoords='offset points',
                 xytext=(0, 0),
                 color=sections.beam_graphs['1A']['color'] * 0.5,
                 va='bottom',
                 ha='center',
                 fontsize=8)

    plt.figure.tight_layout(pad=0)
    plt.figure.show()

    return plt
Esempio n. 3
0
def clip_to_rect(polygon, bbox):
	"""
	clips a polygon to a given bounding box
	takes in a gisutils.Polygon and gisutils.Bounds2D
	"""
	from Polygon.Shapes import Rectangle
	rect = Rectangle(bbox.width, bbox.height)
	rect.shift(bbox.left, bbox.top)
	
	return clip_to_poly(polygon, rect)
Esempio n. 4
0
def operationsExample():
    print('### Operations')
    # create a circle with a hole
    p1 = Circle(1.0) - Circle(0.5)
    # create a square
    p2 = Rectangle(0.7)
    # shift the square a little bit
    p2.shift(0.25, 0.35)
    plist = [p1, p2]
    slist = ['p1', 'p2']

    # addition, the same as logical OR (p1 | p2)
    p = p1 + p2
    p.shift(2.5, 0.0)
    plist.append(p)
    slist.append('p1 + p2 (OR)')

    # subtraction
    p = p1 - p2
    p.shift(5.0, 0.0)
    plist.append(p)
    slist.append('p1 - p2')

    # subtraction
    p = p2 - p1
    p.shift(7.5, 0.0)
    plist.append(p)
    slist.append('p2 - p1')

    # logical AND
    p = p2 & p1
    p.shift(10.0, 0.0)
    plist.append(p)
    slist.append('p2 AND p1')

    # logical XOR
    p = p2 ^ p1
    p.shift(12.5, 0.0)
    plist.append(p)
    slist.append('p2 XOR p1')

    # draw the results of the operations
    writeSVG('Operations.svg',
             plist,
             width=800,
             labels=slist,
             labels_centered=True)
Esempio n. 5
0
def _merge_boxes( boxes ):
    '''
    Merges a list of points specifying contiguous boxes into a single
    Polygon.  Returns the polygon, list of points on the polygon.
    '''
    # bboxArea = the union of all the bounding boxes on the route
    bboxArea = None
    # union all the boxes together
    for i in xrange(0,len(boxes),4):
        # Make a Rectangle out of the width/height of a bounding box
        # longitude = x, latitude = y
        theRect = Rectangle( abs(boxes[i] - boxes[i+2]),
                             abs(boxes[i+1] - boxes[i+3]) )
        theRect.shift( boxes[i+2], boxes[i+3] )
        bboxArea = bboxArea + theRect if bboxArea else theRect

    # turn bboxArea into a list of points
    bboxContour = [list(t) for t in bboxArea.contour( 0 )]

    return bboxArea, bboxContour
Esempio n. 6
0
def searchPoints( request ):
    postData = json.loads(request.raw_post_data)
    rectangles = postData['rectangles']

    # bboxArea = the union of all the bounding boxes on the route
    bboxArea = None
    for i in xrange(0,len(rectangles),4):
        # Make a Rectangle out of the width/height of a bounding box
        # longitude = x, latitude = y
        theRect = Rectangle( abs(rectangles[i] - rectangles[i+2]),
                             abs(rectangles[i+1] - rectangles[i+3]) )
        theRect.shift( rectangles[i+2], rectangles[i+3] )
        bboxArea = bboxArea + theRect if bboxArea else theRect

    bboxArea = [list(t) for t in bboxArea.contour( 0 )]

    # TODO: pull objects out of database using bboxArea
    points = { "points" : [p.position for p in Point.objects( position__within_polygon=bboxArea )] }

    return HttpResponse( json.dumps(points), mimetype="application/json" )
Esempio n. 7
0
 def testLargeOperations(self):
     sheet = Rectangle(1000, 500)
     perf = cloneGrid(Circle(0.5, points=32), 0, 200, 100, 5, 5)
     perfSheet = sheet - perf
     circle = Circle(400, points=512)
     circle.scale(1.0, 0.5)
     circle.shift(500, 250)
     perfCircle = circle & perfSheet
     perfCircle.write('perfcircle.gpf', )
     c, h, p, hf = gpfInfo('perfcircle.gpf')
     self.assertEqual(c, len(perfCircle))
     self.assertEqual(p, perfCircle.nPoints())
     self.assertEqual(hf, True)
Esempio n. 8
0
	def sub_square_polygon(self, pos, width,height, angle=0):
		p1 = Rectangle(width,height)
		p1.shift(-width/2,-height/2)
		p1.rotate(angle)
		p1.shift(pos[0],pos[1])
		if self.poly == None:
			self.poly = p1
			return
		check = self.poly-p1
		if (self.keepsimple and len(check)<2) or not self.keepsimple:
			self.poly = check
Esempio n. 9
0
    def cut(self, x, y):
        """
        Cut an area from the Carpet.
        
        Restrictions:
        - @x and @y must be greater than 0.
        - @x and @y should fit inside the current Carpet.
        """
        successful = False

        will_fit, orientation = self.fits(x, y, with_orientation=True)
        if will_fit and orientation is "xy":
            self.dimensions = self.pointify(self.polygon - Rectangle(x, y))
            self.status = "cut"
            successful = True
        elif will_fit and orientation is "yx":
            self.dimensions = self.pointify(self.polygon - Rectangle(y, x))
            self.status = "cut"
            successful = True
        else:
            print("Will not fit. Aborting.")

        return successful
Esempio n. 10
0
def operationsExample():
    # create a circle with a hole
    p1 = Circle(1.0) - Circle(0.5)
    # create a square
    p2 = Rectangle(0.7)
    # shift the square a little bit
    p2.shift(0.25, 0.35)
    plist = [p1, p2]

    # addition, the same as logical OR (p1 | p2)
    p = p1 + p2
    p.shift(2.5, 0.0)
    plist.append(p)

    # subtraction
    p = p1 - p2
    p.shift(5.0, 0.0)
    plist.append(p)

    # subtraction
    p = p2 - p1
    p.shift(7.5, 0.0)
    plist.append(p)

    # logical AND
    p = p2 & p1
    p.shift(10.0, 0.0)
    plist.append(p)

    # logical XOR
    p = p2 ^ p1
    p.shift(12.5, 0.0)
    plist.append(p)

    # draw the results of the operations
    writeSVG('Operations.svg', plist, width=800)
Esempio n. 11
0
def operationsExample():
    # create a circle with a hole
    p1 = Circle(1.0) - Circle(0.5)
    # create a square
    p2 = Rectangle(0.7)
    # shift the square a little bit
    p2.shift(0.25, 0.35)
    plist = [p1, p2]

    # addition, the same as logical OR (p1 | p2)
    p = p1 + p2
    p.shift(2.5, 0.0)
    plist.append(p)

    # subtraction
    p = p1 - p2
    p.shift(5.0, 0.0)
    plist.append(p)

    # subtraction
    p = p2 - p1
    p.shift(7.5, 0.0)
    plist.append(p)

    # logical AND
    p = p2 & p1
    p.shift(10.0, 0.0)
    plist.append(p)

    # logical XOR
    p = p2 ^ p1
    p.shift(12.5, 0.0)
    plist.append(p)

    # draw the results of the operations
    writeSVG('Operations.svg', plist, width=800)
Esempio n. 12
0
def plot_areas(alpha=0.25):
    plt = make_plot(16, 8)

    order = '1A, 2A, 3A, 1B, 4A, 5A, 2B, 3B, 4B, 6A, 5B, 6B'.split(', ')
    skip = Polygon()
    bounds = Rectangle(39 * 22, 5000)
    for n in order:
        b = sections.beam_graphs[n]
        p = to_poly(b)
        diff = bounds & (p - skip)

        skip += p

        if diff:
            for c in diff:
                plt.fill(*zip(*c), color=b['color'], alpha=alpha)

            plt.annotate(n,
                         xy=diff.center(),
                         textcoords='offset points',
                         xytext=(0, 0) if n[1] == 'B' else (-10, -10),
                         color=b['color'] * 0.5,
                         va='bottom',
                         ha='center',
                         fontsize=8)
            skip += p

    plt.grid()

    plt.axis([0, 39 * 22, 0, 5000])
    plt.set_xlabel('Length / $\mathrm{mm}$')
    plt.set_ylabel('Compression / $\mathrm{N}$')

    plt.figure.tight_layout(pad=0)
    plt.figure.savefig('areas.png', dpi=300)
    plt.figure.show()

    return plt
Esempio n. 13
0
from Polygon import *
from Polygon.Shapes import Circle, Star, Rectangle
from Polygon.IO import writeSVG

p =  Circle(5.5, points=128)
p -= Circle(4.4, points=128)
p += Circle(3.3, points=128) 
p -= Circle(2.2, points=128) 
p += Star(1.1)

l = Rectangle(4, 14)
l.shift(-4.3, -10.5)

r = p ^ l

writeSVG('logo.svg', [r], width=800)
Esempio n. 14
0
from Polygon import *
from Polygon.Shapes import Circle, Star, Rectangle
from Polygon.IO import writeSVG

p = Circle(5.5, points=128)
p -= Circle(4.4, points=128)
p += Circle(3.3, points=128)
p -= Circle(2.2, points=128)
p += Star(1.1)

l = Rectangle(4, 14)
l.shift(-4.3, -10.5)

r = p ^ l

writeSVG('logo.svg', [r], width=800)