def test_fuzz_grammola(): N = 20 for data in generate_fuzz_data(N, vertices=1, spreads=1): try: K = data.spreads[0] diags = data.vertices[0] if diags.parallel(): continue grammola = diags.grammola(K) d1, d2 = diags.line1, diags.line2 try: point = grammola._point_on() except ValueError: continue except ZeroDivisionError: continue assert PointLine(point, d1).quadrance() + PointLine( point, d2).quadrance() - K == 0 d22, K22 = grammola.co_diagonal(d1) d11, K11 = grammola.co_diagonal(d2) assert d22 == d2 assert d11 == d1 assert K22 == K assert K11 == K d1.geometry = True assert_raises(GeometryError, grammola.co_diagonal, d1) except NullLineError: pass
def add_reflection(self, evt): point = self._get_point(self.points) line = self._get_line(self.lines) if point and line: point_line = PointLine(point, line) name = self.name.GetValue() ref = point_line.reflection(), name, "s", self.colours.GetValue() self.parent.object_panel.add_point(ref)
def add_parallel(self, evt): point_ = self._get_point(self.points) line_ = self._get_line(self.lines) if point_ and line_: pl = PointLine(point_, line_) name = self.name.GetValue() parallel = pl.parallel(), name, "o", self.colours.GetValue() self.parent.object_panel.add_line(parallel)
def add_conick(self, evt): k = self.k.GetValue() focus = self._get_point(self.points) directrix = self._get_line(self.lines) if focus and directrix: pl = PointLine(focus, directrix) name = self.name.GetValue() conic = pl.conic(k), name, "x", self.colours.GetValue() self.parent.object_panel.add_conic(conic)
def test_fuzz_altitude(): N = 20 for data in generate_fuzz_data(N, pointlines=1): pl = data.pointlines[0] if pl.line.null(): assert_raises(NullLineError, pl.altitude) else: alt = pl.altitude() assert PointLine(pl.point, alt.line).on() assert Vertex(alt.line, pl.line).perpendicular() assert PointLine(alt.point, pl.line).on()
def focus_directrix(self): """ Calculate the two focus/directrix pairs for this conic as well as the corresponding ratio K. """ #pylint: disable-msg=R0914 from pygeom.pairs import PointLine a, b, c = self.geometry.form D, E, F = self.d, self.e, self.f a1 = a - self.a b1 = b - self.b / 2 AA = 4 * (a * b1 * b1 - 2 * b * a1 * b1 + c * a1 * a1 - a1 * self.geometry.det()) BB = 4 * a1 * ((a * E - b * D) * b1 + (-b * E + c * D) * a1) CC = a1 * a1 * (a * E * E - 2 * b * E * D + c * D * D - 4 * self.geometry.det() * F) c11 = (-BB + (BB * BB - 4 * AA * CC).sqrt()) / (2 * AA) c12 = (-BB - (BB * BB - 4 * AA * CC).sqrt()) / (2 * AA) direc1, direc2 = (Line(a1, b1, c11, self.geometry), Line(a1, b1, c12, self.geometry)) K = (a * b1 * b1 - 2 * b * a1 * b1 + c * a1 * a1) / (a1 * self.geometry.det()) x1 = -(c * (2 * c11 + D) - b * (2 * c11 * b1 / a1 + E)) / (2 * self.geometry.det()) y1 = -(-b * (2 * c11 + D) + a * (2 * c11 * b1 / a1 + E)) / (2 * self.geometry.det()) x2 = -(c * (2 * c12 + D) - b * (2 * c12 * b1 / a1 + E)) / (2 * self.geometry.det()) y2 = -(-b * (2 * c12 + D) + a * (2 * c12 * b1 / a1 + E)) / (2 * self.geometry.det()) focus1 = Point(x1, y1, self.geometry) focus2 = Point(x2, y2, self.geometry) focus_direc_1 = PointLine(focus1, direc1) focus_direc_2 = PointLine(focus2, direc2) return (focus_direc_1, focus_direc_2, K)
def test_construct_quadrance(): f = FiniteField f.base = 37 geom = blue(f) line = Line(f(1), f(1), f(10), geom) point = Point(f(0), f(1), geom) pl = PointLine(point, line) X = pl.construct_quadrance(f(10)) v = pl.construct_spread(f(1) / f(5)) N = 20 for data in generate_fuzz_data(N, pointlines=1, spreads=1): pl = data.pointlines[0] s = data.spreads[0] try: ls = pl.construct_quadrance(s) except ValueError: pass
def test_construct_quadrance(): f = FiniteField f.base = 37 geom = blue(f) line = Line(f(1), f(1), f(10), geom) point = Point(f(0), f(1), geom) pl = PointLine(point, line) X = pl.construct_quadrance(f(10)) v = pl.construct_spread(f(1)/f(5)) N = 20 for data in generate_fuzz_data(N, pointlines=1, spreads=1): pl = data.pointlines[0] s = data.spreads[0] try: ls = pl.construct_quadrance(s) except ValueError: pass
def test_construct_spread(): f = FiniteField f.base = 7 geom = blue(f) line = Line(f(0), f(1), f(0), geom) point = Point(f(1), f(2), geom) pl = PointLine(point, line) v = pl.construct_spread(f(1) / f(5)) N = 20 for data in generate_fuzz_data(N, pointlines=1, spreads=1): pl = data.pointlines[0] s = data.spreads[0] if pl.line.null(): assert_raises(NullLineError, pl.construct_spread, s) else: try: v = pl.construct_spread(s) except ValueError: pass
def test_construct_spread(): f = FiniteField f.base = 7 geom = blue(f) line = Line(f(0), f(1), f(0), geom) point = Point(f(1), f(2), geom) pl = PointLine(point, line) v = pl.construct_spread(f(1)/f(5)) N = 20 for data in generate_fuzz_data(N, pointlines=1, spreads=1): pl = data.pointlines[0] s = data.spreads[0] if pl.line.null(): assert_raises(NullLineError, pl.construct_spread, s) else: try: v = pl.construct_spread(s) except ValueError: pass
def random_pointline(field, geometry): return PointLine(random_point(field, geometry), random_line(field, geometry))
f.base = 13 geometry = red(f) # Create the points A = Point(f(3), f(7), geometry) B = Point(f(4), f(12), geometry) C = Point(f(9), f(2), geometry) # Create the lines of the triangle AB = LineSegment(A, B) AC = LineSegment(A, C) BC = LineSegment(B, C) # Create the altitudes alt_a = PointLine(A, BC.line).altitude().line alt_b = PointLine(B, AC.line).altitude().line alt_c = PointLine(C, AB.line).altitude().line # Calculate the points of intersection of the altitudes O_ab = Vertex(alt_a, alt_b).point O_bc = Vertex(alt_b, alt_c).point O_ca = Vertex(alt_c, alt_a).point # Check that the points are indeed equal assert O_ab == O_bc == O_ca print "Orthocentre:", O_ab # Find the circumcentre C_a = BC.perp_bisector() C_b = AC.perp_bisector()