Ejemplo n.º 1
0
    def giterate(self, fn):
        '''
        Iterate over the generated vectors

        :type fn: func(srcx, srcy, dstx, dsty)
        :param fn: function to call on each iteration
        '''
        # all sizes in mm
        cut_length = 15
        skip_length = 4
        unit_length = cut_length + skip_length
        odd_shift = unit_length / 2
        minimal_width = unit_length * 2
        if self.width < minimal_width:
            raise Exception('width must be bigger than %d' % (minimal_width))
        odd_line = False
        y = 0
        while y < self.height:
            # go over the rows
            x = odd_shift if odd_line else 0
            while x < self.width:
                vector_start = Point(x, y)
                endx = x + cut_length
                if endx > self.width:
                    endx = self.width
                vector_end = Point(endx, y)
                vector = Vector(vector_start, vector_end)
                fn(vector)
                x = x + unit_length
            y += self.spacing
            odd_line = not odd_line
Ejemplo n.º 2
0
    def giterate(self, fn):
        '''
        Iterate over the generated vectors
        This method is simple, but the generated vector order is really inefficient.
        A simplifier should improve the result

        :type fn: func(srcx, srcy, dstx, dsty)
        :param fn: function to call on each iteration
        '''

        #
        # for each 2 adjacent vectors
        #
        for i in range(len(self._points)):
            s = self._points[i]
            d = self._points[(i + 1) % len(self._points)]
            self._l.debug('main vectors: %s' % Vector(s, d))
            sxst = s.x / self._npoints  # source x step
            syst = s.y / self._npoints  # source y step
            dxst = d.x / self._npoints  # dest x step
            dyst = d.y / self._npoints  # dest y step
            #
            # generate each internal vector
            #
            for p in range(1, self._npoints):
                sp = p  # current point in source
                dp = self._npoints - p  # current points in dest
                sx = sxst * sp
                sy = syst * sp
                dx = dxst * dp
                dy = dyst * dp
                s = Point(sx, sy)
                d = Point(dx, dy)
                fn(Vector(s, d))
Ejemplo n.º 3
0
def test_top_down_tbone_near_miss_aft():
    _test_collision(direction_1=directions.FORWARD,
                    pos_1=Point(-10, 0, 0),
                    throttle_1=0.0,
                    direction_2=directions.DECK,
                    pos_2=Point(0, 0, 100),
                    throttle_2=1.0,
                    expected_collision=False)
Ejemplo n.º 4
0
 def test_helix(self):
     cyl1 = SurfaceCylinder('cyl1', 1., 2.)
     cyl2 = SurfaceCylinder('cyl2', 2., 1.)
     field = 3.8
     particle = Particle(LorentzVector(2., 0, 1, 5), Point(0., 0., 0.), -1)
     debug_info = helix.propagate_one(particle, cyl1, field)
     particle = Particle(LorentzVector(0., 2, 1, 5), Point(0., 0., 0.), -1)
     debug_info = helix.propagate_one(particle, cyl1, field)
Ejemplo n.º 5
0
def test_rear_near_miss_port():
    _test_collision(direction_1=directions.FORWARD,
                    pos_1=Point(0, -10, 0),
                    throttle_1=1.0,
                    direction_2=directions.FORWARD,
                    pos_2=Point(100, 0, 0),
                    throttle_2=0.5,
                    expected_collision=False)
Ejemplo n.º 6
0
def test_head_on_near_miss_deck():
    _test_collision(direction_1=directions.FORWARD,
                    pos_1=Point(-100, 0, -10),
                    throttle_1=1.0,
                    direction_2=directions.AFT,
                    pos_2=Point(100, 0, 0),
                    throttle_2=1.0,
                    expected_collision=False)
Ejemplo n.º 7
0
 def generate_resistor_box(self, fn):
     '''this is the box in the middle, when the resistor body rests'''
     w = self.resistor_length
     h = self.dim.h - ((self.margin_top + self.margin_bottom) / 2)
     x = (self.dim.w - self.resistor_length) / 2
     y = self.margin_top / 2
     for v in Path.do_square(Point(x, y), Point(w, h)):
         fn(v)
Ejemplo n.º 8
0
def test_level_tbone_near_miss_sb():
    _test_collision(direction_1=directions.FORWARD,
                    pos_1=Point(0, 10, 0),
                    throttle_1=0.0,
                    direction_2=directions.STARBOARD,
                    pos_2=Point(0, -100, 0),
                    throttle_2=1.0,
                    expected_collision=False)
Ejemplo n.º 9
0
def test_rear_collision():
    _test_collision(
        direction_1=directions.FORWARD,
        pos_1=Point(0, 0, 0),
        throttle_1=1.0,
        direction_2=directions.FORWARD,
        pos_2=Point(100, 0, 0),
        throttle_2=0.5,
    )
Ejemplo n.º 10
0
def test_top_down_tbone_collision():
    _test_collision(
        direction_1=directions.FORWARD,
        pos_1=Point(0, 0, 0),
        throttle_1=0.0,
        direction_2=directions.DECK,
        pos_2=Point(0, 0, 100),
        throttle_2=1.0,
    )
Ejemplo n.º 11
0
def test_level_tbone_collision():
    _test_collision(
        direction_1=directions.FORWARD,
        pos_1=Point(0, 0, 0),
        throttle_1=0.0,
        direction_2=directions.STARBOARD,
        pos_2=Point(0, -100, 0),
        throttle_2=1.0,
    )
Ejemplo n.º 12
0
def test_angular_collision():
    _test_collision(
        direction_1=directions.FORWARD,
        pos_1=Point(-100, 0, 0),
        throttle_1=1.0,
        direction_2=directions.AFT,
        pos_2=Point(100, 0, 0),
        throttle_2=1.0,
    )
Ejemplo n.º 13
0
    def __init__(self,
                 planckType,
                 planckRadius,
                 point=Point(0, 0, 0),
                 vector=Vector(0, 0, 0),
                 chargeMagnitude=Fraction(1, 6)):
        # process args
        if planckType == 'electrino':
            self.planckType = planckType
            self.charge = chargeMagnitude * -1
        elif planckType == 'positrino':
            self.planckType = planckType
            self.charge = chargeMagnitude
        else:
            raise TypeError('planckType must be electrino OR positrino')

        if isinstance(point, Point):
            self.point = point
        if isinstance(vector, Vector):
            self.vector = vector

        self.electricFieldTime = 0
        self.electricFieldRadius = 0
        self.magneticFieldTime = 0
        self.magneticFieldRadius = 0
Ejemplo n.º 14
0
def main():
    opts = docopt.docopt(__doc__)
    x = int(opts['<x>'])
    y = int(opts['<y>'])
    w = int(opts['<w>'])
    h = int(opts['<h>'])
    spacing = float(opts['<spacing>'])
    cut_feed = 600 if not opts['--cut_feed'] else int(opts['--cut_feed'])
    passing_feed = 800 if not opts['--passing_feed'] else int(
        opts['--passing_feed'])
    outfilename = opts['<outfile>']
    if not outfilename:
        outfilename = 'os_%f_%d_%d_%d_%d.ngc' % (spacing, h, w, x, y)
    logging.getLogger('MainApp').info('Gcode file name: %s' % (outfilename))
    p = HingePattern(height=h, width=w, spacing=spacing)
    s = PathSimplifier()
    comment = '''Generated by hinge.py with parameters:
spacing: %f
height: %d
width: %d''' % (spacing, h, w)
    g = GCodeGenerator(open(outfilename, 'w'), comment, cut_feed, passing_feed)
    p.giterate(s.add_vector)
    vectors = s.simplify()
    #
    # adjust all vectors to be negative only
    #
    vectors = add_to_vectors(vectors, -Point(x + w, y + h))
    g.generate(vectors)
def distancePointSegment(a,Vbc,b,c): #returns min_distance between bc and a and the point of intersection of perpendicular from a on bc
	
	Vab=Vector.from_points(b, a)
	Vac=Vector.from_points(c, a)
	zero_vector=Point(0,0,0)
	min_distance=100
	final_point=[]
	type=[]
	if Vbc.magnitude()<.000001:
		return [9999999,[a.x,a.y]]
	if abs(Vab.dot(Vbc)/Vbc.magnitude())<= Vbc.magnitude() and abs(Vac.dot(Vbc)/Vbc.magnitude())<= Vbc.magnitude():
		min_distance=(Vab.cross(Vbc)).magnitude()/Vbc.magnitude()
		
		perpendicular_point_vector=Vbc.multiply(abs(Vab.dot(Vbc))/Vbc.magnitude()/Vbc.magnitude())
		final_point=perpendicular_point_vector.sum(Vector.from_points(zero_vector,b))
		type="middle"
	else :
		min_distance=min([Vab.magnitude(),Vac.magnitude()])
		if min_distance==Vab.magnitude():
			final_point=Vector.from_points(zero_vector, b)
			type="vertex"
		else:
			final_point=Vector.from_points(zero_vector, c)
			type="vertex"

	return [min_distance,[final_point.x,final_point.y]]
Ejemplo n.º 16
0
def get_normal(tri):
    """in: 3 verts, out normal (nx, ny,nz) with length 1
    """
    (v0, v1, v2) = tri
    p0 = Point.from_list(v0.get())
    p1 = Point.from_list(v1.get())
    p2 = Point.from_list(v2.get())
    a = Vector.from_points(p1, p0)
    b = Vector.from_points(p1, p2)
    #print p0,p1, p2
    #print a,b
    c = a.cross(b)
    #print c
    m = float(c.magnitude())

    normal = [c.x / m, c.y / m, c.z / m]
    return normal
Ejemplo n.º 17
0
 def getFaceNormal(self, face):
     points = []
     for v in face:
         points.append(Point(v[0], v[1], v[2]))
     vecA = Vector.from_points(points[0], points[1])
     vecB = Vector.from_points(points[0], points[2])
     vecResult = Vector.cross(vecA, vecB)
     return vecResult
def findDistanceBetweenSegments(ab,a,af,bb,b,bf):# returns geo distance between two adjacent line segments for two polygons in m
	
	z_point=Point(0,0,0)
	Paf=Point(af[0],af[1],0)
	Pa=Point(a[0],a[1],0)
	Pab=Point(ab[0],ab[1],0)
	Pbf=Point(bf[0],bf[1],0)
	Pb=Point(b[0],b[1],0)
	Pbb=Point(bb[0],bb[1],0)
	compare=[]
	dist=[]
	
	temp_result=findShortestDistanceSegments(Pab, Pa,Pbb, Pb) #[[min_distance,[final_point.x,final_point.y]],a2]
	compare.append([temp_result[0][1],temp_result[1]])
	dist.append(temp_result[0][0])
	
	temp_result=findShortestDistanceSegments(Pab, Pa,Pb, Pbf)
	compare.append([temp_result[0][1],temp_result[1]])
	dist.append(temp_result[0][0])
	
	temp_result=findShortestDistanceSegments(Pa, Paf,Pb, Pbb)
	compare.append([temp_result[0][1],temp_result[1]])
	dist.append(temp_result[0][0])
	
	temp_result=findShortestDistanceSegments(Pa, Paf,Pb, Pbf)
	compare.append([temp_result[0][1],temp_result[1]])
	dist.append(temp_result[0][0])
	
	min_index=dist.index(min(dist))
	
	final_result=compare[min_index]
	
	return haversine(cartesianToGeo(final_result[0][0],final_result[0][1]),cartesianToGeo(final_result[1].x,final_result[1].y))*1000
Ejemplo n.º 19
0
def test_can_sense_at_angle_yaw():
    _assert_can_detect(
        target_pos=Point(10, 10, 0),
        scan_direction=STARBOARD,
        sensor_orientation={
            PITCH: 45,
            YAW: 67.5
        },
    )
Ejemplo n.º 20
0
def test_forward_acceleration_45_pitch():
    _test_acceleration(direction=directions.FORWARD,
                       expected_position=Point(7.0711, 0.00, -7.0711),
                       orientation={
                           directions.YAW: 0,
                           directions.ROLL: 0,
                           directions.PITCH: 45
                       },
                       keep_mass=False)
Ejemplo n.º 21
0
def test_can_sense_at_angle_pitch():
    _assert_can_detect(
        target_pos=Point(0, 10, 10),
        scan_direction=STARBOARD,
        sensor_orientation={
            PITCH: 15,
            YAW: 45
        }
    )
Ejemplo n.º 22
0
def test_forward_acceleration_90_pitch():
    _test_acceleration(direction=directions.FORWARD,
                       expected_position=Point(0.00, 0.00, -10.00),
                       orientation={
                           directions.YAW: 0,
                           directions.ROLL: 0,
                           directions.PITCH: 90
                       },
                       keep_mass=False)
Ejemplo n.º 23
0
 def __init__(self, *args, **kwargs):
     self.position = kwargs.pop('position', Point(0, 0, 0))
     self.current_vector = kwargs.pop('current_vector', Vector(0, 0, 0))
     self.mass = kwargs.pop('mass', 0)
     self.yaw_speed = kwargs.pop('yaw_speed', 0)
     self.roll_speed = kwargs.pop('roll_speed', 0)
     self.pitch_speed = kwargs.pop('pitch_speed', 0)
     self.integrity = 1.0
     self._acceleration_vectors = []
Ejemplo n.º 24
0
    def test_straightline(self):
        origin = Point(0,0,0)
        cyl1 = SurfaceCylinder('cyl1', 1, 2)
        cyl2 = SurfaceCylinder('cyl2', 2, 1)

        particle = Particle( LorentzVector(1, 0, 1, 2.), origin, 0)
        straight_line.propagate_one( particle, cyl1 )
        straight_line.propagate_one( particle, cyl2 )
        self.assertEqual( len(particle.points), 3)
        # test extrapolation to barrel
        self.assertAlmostEqual( particle.points['cyl1'].Perp(), 1. )
        self.assertAlmostEqual( particle.points['cyl1'].Z(), 1. )
        # test extrapolation to endcap
        self.assertAlmostEqual( particle.points['cyl2'].Z(), 1. )
        
        # testing extrapolation to -z 
        particle = Particle( LorentzVector(1, 0, -1, 2.), origin, 0)
        # import pdb; pdb.set_trace()
        straight_line.propagate_one( particle, cyl1 )
        straight_line.propagate_one( particle, cyl2 )
        self.assertEqual( len(particle.points), 3)
        self.assertAlmostEqual( particle.points['cyl1'].Perp(), 1. )
        # test extrapolation to endcap
        self.assertAlmostEqual( particle.points['cyl1'].Z(), -1. )
        self.assertAlmostEqual( particle.points['cyl2'].Z(), -1. )

        # extrapolating from a vertex close to +endcap
        particle = Particle( LorentzVector(1, 0, 1, 2.),
                             Point(0,0,1.5), 0)
        straight_line.propagate_one( particle, cyl1 )
        self.assertAlmostEqual( particle.points['cyl1'].Perp(), 0.5 )
        
        # extrapolating from a vertex close to -endcap
        particle = Particle( LorentzVector(1, 0, -1, 2.),
                             Point(0,0,-1.5), 0)
        straight_line.propagate_one( particle, cyl1 )
        self.assertAlmostEqual( particle.points['cyl1'].Perp(), 0.5 )
        
        # extrapolating from a non-zero radius
        particle = Particle( LorentzVector(0, 0.5, 1, 2.),
                             Point(0,0.5,0), 0)
        straight_line.propagate_one( particle, cyl1 )
        self.assertAlmostEqual( particle.points['cyl1'].Perp(), 1. )
        self.assertAlmostEqual( particle.points['cyl1'].Z(), 1. )
Ejemplo n.º 25
0
 def __init_old__(self):
     self.resistor_length = 6
     self.bend_length_min = 4
     self.bend_length_max = 10
     self.bend_length_step = 1
     self.bend_count = (self.bend_length_max - self.bend_length_min +
                        1) / self.bend_length_step
     self.bend_cut_height = 0.4
     self.spacing_between_lines = 4
     self.spacing_middle_box_top = 5
     self.spacing_middle_box_bottom = 5
     self.spacing_left = 2
     self.spacing_right = 2
     self.spacing_side = 5
     middle_box_height = (self.bend_count + 1) * self.spacing_between_lines
     self.middle_box_dim = Point(self.resistor_length, middle_box_height)
     self.middle_box_loc = Point(self.spacing_left + self.bend_length_max,
                                 self.spacing_middle_box_top)
     self.dim = self.middle_box_loc + self.middle_box_dim + Point(
         self.bend_length_max + self.spacing_right,
         self.spacing_middle_box_bottom)
Ejemplo n.º 26
0
def get_init_data():
    # create g1 as example 
    p1 = Patch(1100, 1400, Point(2200, 2900, 0), 'E')
    p2 = Patch(2100, 1400, Point(3800, 3200, 0), 'BA')
    p3 = Patch(1100, 1600, Point(2200, 4400, 0), 'D')
    p4 = Patch(1100, 1600, Point(1100, 1400, 0), 'K')
    p5 = Patch(2100, 3100, Point(3800, 5400, 0), 'BR')
    p6 = Patch(2100, 1600, Point(1500, 6000, 0), 'L')

    g1 = PlanGraph()
    g1.addPatch(p1)
    g1.addPatch(p2)
    g1.addPatch(p3)
    g1.addPatch(p4)
    g1.addPatch(p5)
    g1.addPatch(p6)
    g1.addConn((p1,p2))
    g1.addConn((p1,p3))
    g1.addConn((p1,p4))
    g1.addConn((p3,p4))
    g1.addConn((p3,p5))
    g1.addConn((p3,p6))
    g1.addConn((p4,p6))

    return g1
Ejemplo n.º 27
0
    def generate_bending_cuts(self, fn):
        '''Generate the cuts for the resistor bending'''
        prev_left = self.left_vector.point_for_y(0)
        prev_right = self.right_vector.point_for_y(0)
        for i in range(self.bend_count):
            y = self.get_bend_y(i)
            y1 = y - self.bend_cut_height / 2
            y2 = y + self.bend_cut_height / 2

            # left part
            xend = self.left_vector.x_for_y(y) + self.margin_sides
            p1 = self.left_vector.point_for_y(y1)
            p2 = Point(xend, y1)
            p3 = Point(xend, y2)
            p4 = self.left_vector.point_for_y(y2)

            fn(Vector(p1, p2))
            fn(Vector(p2, p3))
            fn(Vector(p3, p4))
            # add diagonal part the comes above it
            fn(Vector(prev_left, p1))
            prev_left = p4

            # right part
            xstart = self.right_vector.x_for_y(y) - self.margin_sides
            p1 = self.right_vector.point_for_y(y1)
            p2 = Point(xstart, y1)
            p3 = Point(xstart, y2)
            p4 = self.right_vector.point_for_y(y2)

            fn(Vector(p1, p2))
            fn(Vector(p2, p3))
            fn(Vector(p3, p4))
            # add diagonal part the comes above it
            fn(Vector(prev_right, p1))
            prev_right = p4

        fn(Vector(prev_left, self.left_vector.point_for_y(self.dim.h)))
        fn(Vector(prev_right, self.right_vector.point_for_y(self.dim.h)))
Ejemplo n.º 28
0
def test_port_acceleration_45_roll():
    _test_acceleration(direction=directions.PORT,
                       expected_position=Point(
                           0.00,
                           -7.0711,
                           -7.0711,
                       ),
                       orientation={
                           directions.YAW: 0,
                           directions.ROLL: 45,
                           directions.PITCH: 0
                       },
                       keep_mass=False)
Ejemplo n.º 29
0
def test_overhead_acceleration_pitch_no_change():
    _test_acceleration(direction=directions.STARBOARD,
                       expected_position=Point(
                           0.00,
                           10.00,
                           0.00,
                       ),
                       orientation={
                           directions.YAW: 0,
                           directions.ROLL: 0,
                           directions.PITCH: 90
                       },
                       keep_mass=False)
Ejemplo n.º 30
0
    def generate_bending_tunnels(self, fn):
        for i in range(self.bend_count):
            y = self.get_bend_y(i)
            length = self.get_bend_length(i)

            # left tunnel
            xstart = self.left_vector.x_for_y(y) + self.margin_sides
            xend = xstart + length
            fn(
                Vector(Point(xstart, y), Point(xend, y), {
                    'pre_command': 'S400',
                    'post_command': 'S1000'
                }))

            # right tunnel
            xend = self.right_vector.x_for_y(y) - self.margin_sides
            xstart = xend - length
            fn(
                Vector(Point(xstart, y), Point(xend, y), {
                    'pre_command': 'S400',
                    'post_command': 'S1000'
                }))