Esempio n. 1
0
    def testInterceptWithSameOrigin(self):
        for i in range(0, 50):
            point = [
                random.random() * 1000 - 500,
                random.random() * 1000 - 500
            ]
            angle1 = 2 * math.pi * random.random()
            angle2 = 2 * math.pi * random.random()
            if angle1 % math.pi == angle2 % math.pi:
                continue

            g = geo.Line(angle1, point)
            h = geo.Line(angle2, point)
            m = g.intercept(h)
            self.assertEqual(m, point)
Esempio n. 2
0
    def on_canvas_mouse_release_event(self, event):
        mouse_point = self.window_to_point(event.pos())
        found = False

        if self.fold:
            line = geoutil.line.perpendicular(self.fold, geo.Point(0.5, 0.5))
            point = geoutil.line.intersect(line, self.fold)
            threshold = self.selection_threshold()
            if (mouse_point - point).magnitude2() < threshold * threshold:
                self.fold = geo.Line(-self.fold.normal, -self.fold.offset)
                found = True

        if not found:
            if self.highlight:
                if self.highlight in self.selected:
                    self.selected.remove(self.highlight)
                else:
                    if self.num_selected(type(self.highlight)) < 2:
                        self.selected.append(self.highlight)
                        self.highlight = None
            else:
                self.selected.clear()

        self.ui.canvas.update()
        self.update_actions()
Esempio n. 3
0
    def __init__(self, plat_line, hauteur, culasse, ior):
        self.Faces = []
        self.ior = ior
        
        table_line = geo.Line(0, [0, hauteur])
        
        # interception entre plat et table
        inter_plat_table = table_line.intercept(plat_line)
        if not inter_plat_table:
            return

        table_hsize = max(inter_plat_table[0], 0)
        table = geo.Segment(table_line, x=[-table_hsize, table_hsize])
        plat = geo.Segment(plat_line, x=[1, table_hsize])

        self.addFace("table", table, True)
        self.addFace("platG", plat, True)
        self.addFace("platD", plat.getYSymetric(), True)

        # Culasse
        xstart = 1
        for i,line in enumerate(culasse):
            if i+1 < len(culasse):
                nline = culasse[i+1]
                intercept = line.intercept(nline)
                xend = intercept[0]
            else:
                xend = 0
            
            s = geo.Segment(line, x=[xstart, xend])
            self.addFace("cplat" + str(i) + "G", s, False)
            self.addFace("cplat" + str(i) + "D", s.getYSymetric(), False)
            xstart = xend
Esempio n. 4
0
    def testGetOutRays(self):
        line = geo.Line(0, [0, 0])
        segment = geo.Segment(line, x=[0, 2])
        i1 = 1
        for i in range(0, 50):
            i2 = 0.5 + random.random()
            angle = random.random() * 2 * math.pi

            ray = geo.Line(angle, [1, 0])
            rays = segment.getOutRays(ray, i1, i2)

            incident_angle = math.fabs(angle - math.pi / 2) % math.pi
            incident_quarter = angle // (math.pi / 2)

            reflected = rays['reflected']
            reflected_angle = math.fabs(reflected.angle -
                                        math.pi / 2) % math.pi
            reflected_quarter = reflected.angle // (math.pi / 2)
            self.assertAlmostEqual(incident_angle,
                                   reflected_angle,
                                   msg="Bad reflected angle")
            # Check that the reflected ray is on the right quarter of the trigo circle
            self.assertNotEqual(
                incident_quarter % 2,
                reflected_quarter % 2,
                msg="Reflected ray is the same as incident ray (%s)" % {
                    'angle': angle,
                    'i2': i2
                })

            if 'refracted' in rays:
                refracted = rays['refracted']
                refracted_angle = math.fabs(refracted.angle -
                                            math.pi / 2) % math.pi
                refracted_quarter = refracted.angle // (math.pi / 2)
                self.assertAlmostEqual(i1 * math.sin(incident_angle),
                                       i2 * math.sin(refracted_angle))
                self.assertTrue(
                    math.fabs(refracted_quarter - incident_quarter) == 2,
                    msg="Refracted ray is not on the right quarter (%r)" % {
                        'angle': angle,
                        'i2': i2,
                        'ray': ray,
                        'rays': rays
                    })
Esempio n. 5
0
def O3(line0, line1):
    theta0 = math.atan2(line0.normal.y, line0.normal.x)
    theta1 = math.atan2(line1.normal.y, line1.normal.x)
    theta = (theta0 + theta1) / 2

    cos = math.cos(theta)
    sin = math.sin(theta)
    lines = []
    for normal in (geo.Vector(cos, sin), geo.Vector(-sin, cos)):
        if abs(line0.offset) > abs(MAX_DISTANCE * (line0.normal * normal)):
            continue
        if abs(line1.offset) > abs(MAX_DISTANCE * (line1.normal * normal)):
            continue

        t0 = line0.offset / (line0.normal * normal)
        t1 = line1.offset / (line1.normal * normal)
        offset = (t0 + t1) / 2
        lines.append(geo.Line(normal, offset))

    return lines
Esempio n. 6
0
def from_point_normal(point, normal):
    offset = normal * point.vector()
    return geo.Line(normal, offset)
Esempio n. 7
0
def perpendicular(line, point):
    normal = geoutil.vector.perpendicular(line.normal)
    offset = normal * point.vector()
    return geo.Line(normal, offset)
Esempio n. 8
0
def parallel(line, point):
    normal = line.normal
    offset = normal * point.vector()
    return geo.Line(normal, offset)
Esempio n. 9
0
#!/bin/env python
import geo
from math import pi

g = geo.Line(pi / 2, [1, 0])
h = geo.Line(0, [0, 1])
m = g.intercept(h)
print "%s intercept %s in %s" % (g, h, m)

g = geo.Line(pi / 4, [1, 0])
h = geo.Line(3 * pi / 4, [-1, 0])
m = g.intercept(h)
print "%s intercept %s in %s" % (g, h, m)

line = geo.Line(pi / 4, [0, 0])
segment = geo.Segment(line, x=[0, 1])
print segment

line = geo.Line(pi / 2, [1, 0])
segment = geo.Segment(line, y=[0, 1])
print segment

line = geo.Line(0, [0, 0])
segment = geo.Segment(line, x=[0, 2])
ray = geo.Line(pi / 2, [1, 0])
rays = segment.getOutRays(ray, 1, 1.9)
print "Segment: %s, Ray: %s\n * Reflected: %s\n * Refracted: %s" % (
    segment, ray, rays['reflected'], rays['refracted'])

line = geo.Line(0, [0, 0])
segment = geo.Segment(line, x=[0, 2])
Esempio n. 10
0
def O2(point0, point1):
    normal = (point1 - point0).normalize()
    line0 = geoutil.line.from_point_normal(point0, normal)
    line1 = geoutil.line.from_point_normal(point1, normal)
    offset = (line0.offset + line1.offset) / 2
    return geo.Line(normal, offset)