コード例 #1
0
    def test_0():
        c = Circle((0, 0), 1)

        assert c.tangent(Point(0, 1)) == Line(0, 1, -1)
        assert c.tangent(Point(0, -1)) == Line(0, -1, -1)
        assert c.tangent(Point(1, 0)) == Line(1, 0, -1)
        assert c.tangent(Point(-1, 0)) == Line(-1, 0, -1)
コード例 #2
0
    def test_0():
        c = Circle((0, 0), 1)

        assert c.normal(Point(0, 1)) == Line(1, 0, 0)
        assert c.normal(Point(0, -1)) == Line(1, 0, 0)
        assert c.normal(Point(1, 0)) == Line(0, 1, 0)
        assert c.normal(Point(-1, 0)) == Line(0, 1, 0)
コード例 #3
0
    def test_1():
        p1 = Point(0, 0)
        p2 = Point(1, 0)
        p3 = Point(1 * cmath.cos(cmath.pi / 3), 1 * cmath.sin(cmath.pi / 3))
        t = triangle.Triangle(p1, p2, p3)

        assert_almost_equal(t.circum_radius(), 1 / cmath.sqrt(3))
コード例 #4
0
    def test_0():
        p1 = Point(0, 0)
        p2 = Point(1, 0)
        p3 = Point(0, 1)
        t = triangle.Triangle(p1, p2, p3)

        assert_almost_equal(t.circum_radius(), 1 / (2**0.5))
コード例 #5
0
    def test_1():
        p1 = Point(0, 0)
        p2 = Point(1, 0)
        p3 = Point(0, 1)
        t = triangle.Triangle(p1, p2, p3)

        assert_almost_equal(t.in_radius(), 1 / (2 + cmath.sqrt(2)))
コード例 #6
0
    def test_0():
        p1 = Point(1, 2)
        p2 = Point(3, 4)
        assert geometry.slope(p1, p2) == 1

        p1 = Point(4, -6)
        p2 = Point(-2, -5)
        assert geometry.slope(p2, p1) == -1/6
コード例 #7
0
    def test_1():
        p1 = Point(1, 2)
        p2 = Point(1, 3)
        assert geometry.distance(p1, p2) == 1

        p1 = Point(2.0, 1)
        p2 = Point(3.0, 1)
        assert geometry.distance(p1, p2) == 1
コード例 #8
0
    def test_1():
        p1 = Point(-1, 3)
        p2 = Point(1, -3)

        p_computed = geometry.section(p1, p2, (2, 3))
        p_actual = Point(-1/5, 3/5)

        assert_array_almost_equal(p_computed(), p_actual(), decimal=6)
コード例 #9
0
    def test_0():
        p1 = Point(1, 2)
        p2 = Point(3, 4)
        assert geometry.line_equation(p1, p2) == Line(1, -1, 1)

        p1 = Point(4, -6)
        p2 = Point(-2, -5)
        assert geometry.line_equation(p1, p2) == Line(1, 6, 32)
コード例 #10
0
    def test_1():
        p1 = Point(1, 2)
        p2 = Point(1, 3)
        assert geometry.line_equation(p1, p2) == Line(1, 0, -1)

        p1 = Point(1, 2)
        p2 = Point(2, 2)
        assert geometry.line_equation(p1, p2) == Line(0, 1, -2)
コード例 #11
0
 def test_0():
     p1 = Point(0, 1)
     p2 = Point(1, 0)
     p3 = Point(0, 0)
     t = triangle.Triangle(p1, p2, p3)
     assert compare_points(
         t.in_center(),
         Point(1 / (2 + cmath.sqrt(2)), 1 / (2 + cmath.sqrt(2))))
コード例 #12
0
    def test_1():

        from test import compare_lines

        c = Circle((0, 0), 1)
        p0 = Point(cmath.cos(cmath.pi / 4), cmath.sin(cmath.pi / 4))
        p1 = Point(-cmath.cos(cmath.pi / 4), cmath.sin(cmath.pi / 4))

        assert compare_lines(c.normal(p0), Line(1, -1, 0))
        assert compare_lines(c.normal(p1), Line(1, 1, 0))
コード例 #13
0
    def test_1():
        p1 = Point(2, 0)
        p2 = Point(2, 4)
        p = Point(0, 0)
        l = Line.construct(p1, p2)
        assert geometry.line_distance(p, l) == 2
        assert l.distance(p) == 2

        l = Line(0, 1, -3)
        assert l.distance(p) == 3
コード例 #14
0
    def test_1():

        from test import compare_lines

        c = Circle((0, 0), 1)

        p = Point(cmath.cos(cmath.pi / 4), cmath.sin(cmath.pi / 4))
        p1 = Point(cmath.sqrt(2), 0)
        p2 = Point(0, cmath.sqrt(2))

        assert compare_lines(c.tangent(p), Line.construct(p1, p2))
コード例 #15
0
    def test_1():
        p = Point(-1, 3)
        l = Line(3, -4, -16)

        p_actual = l.foot_perpendicular(p)
        p_image = l.image(p)

        p_desired = Point(68/25, -49/25)

        assert_array_almost_equal(p_actual(), p_desired(), decimal=6)
        assert geometry.midpoint(p, p_image) == p_actual 
コード例 #16
0
    def test_1():

        p1 = Point(1, 2)
        p2 = Point(2, 2)

        assert geometry.slope(p1, p2) == 0

        p1 = Point(1, 2)
        p2 = Point(1, 3)
        try:
            geometry.slope(p1, p2)
        except ZeroDivisionError:
            assert True
コード例 #17
0
    def __init__(self, center: Union[Point, tuple, list], radius: float):
        """Initialize the circle."""
        if isinstance(center, tuple) or isinstance(center, list):
            assert len(center) == 2, "Center must be a 2-tuple or list"
            center = Point(center[0], center[1])

        self.center = center
        self.radius = radius
コード例 #18
0
    def test_0():
        p1 = Point(1, 2)
        p2 = Point(3, 4)
        l = Line.construct(p1, p2)
        p = Point(2, 2)
        assert geometry.foot_perpendicular(p, l) == Point(1.5, 2.5)

        p = Point(2, 3)
        assert geometry.foot_perpendicular(p, l) == Point(2, 3)
コード例 #19
0
    def intersetion(self, other) -> Union[Point, None]:
        """Return the intersection point of the circle and the other circle."""
        if isinstance(other, Circle):
            c1 = self.center
            c2 = other.center

            m = geometry.slope(c1, c2)
            theta = cmath.atan(m)

            d = geometry.distance(c1, c2)

            if d == self.radius + other.radius:
                """Two circles are touching each other"""
                x = c1.x + self.radius * cmath.cos(theta)
                y = c1.y + self.radius * cmath.sin(theta)
                return Point(x, y)

            elif d < self.radius + other.radius:
                """Two circles intersect"""
                r1 = self.radius
                r2 = other.radius

                theta = cmath.asin(r2 / d)

                x = c1.x + r1 * cmath.cos(theta)
                y = c1.y + r1 * cmath.sin(theta)

                p1 = Point(x, y)
                l = Line.construct(c1, c2)
                p2 = l.image(p1)

                return (p1, p2)
            else:
                return None

        else:
            raise ValueError("Can only intersect with another circle")
コード例 #20
0
    def test_0():
        p1 = Point(1, 2)
        p2 = Point(3, 4)
        assert geometry.distance(p1, p2) == 2*(2**0.5)

        p1 = Point(4, -6)
        p2 = Point(-2, -5)
        assert geometry.distance(p2, p1) ==  (37**0.5)

        p1 = Point(1.3, 2.3)
        p2 = Point(1.4, 2.4)

        d_output = geometry.distance(p1, p2)
        d_actual = 0.1*(2**0.5)

        assert_array_almost_equal(d_output, d_actual, decimal=6)
コード例 #21
0
 def in_center(self):
     """Return the inCenter of the triangle."""
     s = self.perimeters()
     i = (self.a * self.points[2].x + self.b * self.points[0].x + self.c * self.points[1].x) / s, \
             (self.a * self.points[2].y + self.b * self.points[0].y + self.c * self.points[1].y) / s
     return Point(i[0], i[1])
コード例 #22
0
 def centroid(self):
     """Return the centroid of the triangle."""
     x = (self.points[0].x + self.points[1].x + self.points[2].x) / 3
     y = (self.points[0].y + self.points[1].y + self.points[2].y) / 3
     return Point(x, y)
コード例 #23
0
ファイル: visu.py プロジェクト: Lakshmikanth2001/ElectricPy
    def _build_circle(a1, a2, circle_type, V, P = None, Q = None, S = None, power_factor = None, V_ref = None):

        k = (abs(V)**2)*abs(a1)/abs(a2)
        alpha = cmath.phase(a1)
        beta = cmath.phase(a2)

        if circle_type == "receiving_end":
            center = Point(-k*cmath.cos(alpha - beta), -k*cmath.sin(alpha - beta))

        elif circle_type == "sending_end":
            center = Point(k*cmath.cos(alpha -beta), -k*cmath.sin(alpha - beta))

        if V_ref != None and P != None and Q != None:
            radius = abs(V)*abs(V_ref)/(abs(a2))
            operation_point = Point(P, Q)

        elif V_ref != None and S != None:
            radius = abs(V)*abs(V_ref)/(abs(a2))
            operation_point = Point(S.real, S.imag)

        elif P != None and Q != None:
            radius = geometry.distance(center, Point(P, Q))
            operation_point = Point(P, Q)

        elif S != None:
            radius = geometry.distance(center, Point(S.real, S.imag))
            operation_point = Point(S.real, S.imag)

        elif P != None and power_factor != None:

            Q = P*cmath.sqrt(1/power_factor**2 - 1).real

            if power_factor < 0:
                Q = -Q

            radius = geometry.distance(center, Point(P, Q))
            operation_point = Point(P, Q)

        elif Q != None and power_factor != None:
            P = Q/cmath.sqrt(1/power_factor**2 - 1).real
            radius = geometry.distance(center, Point(P, Q))
            operation_point = Point(P, Q)

        else:
            raise AttributeError("Enought attributes to calculate not found")

        return radius, center, operation_point
コード例 #24
0
 def test_1():
     p1 = Point(-3, 0)
     p2 = Point(0, 3)
     l = perpendicular_bisector(p1, p2)
     assert l == Line(1, 1, 0)
コード例 #25
0
 def test_2():
     p1 = Point(3, 0)
     p2 = Point(5, 0)
     l = perpendicular_bisector(p1, p2)
     assert l == Line(1, 0, -4)
コード例 #26
0
 def test_3():
     p1 = Point(0, 3)
     p2 = Point(0, 5)
     l = perpendicular_bisector(p1, p2)
     assert l == Line(0, 1, -4)
コード例 #27
0
 def test_0():
     p1 = Point(1, 2)
     p2 = Point(3, 4)
     p3 = Point(5, 6)
     assert geometry.colinear(p1, p2, p3)
コード例 #28
0
 def test_1():
     p1 = Point(1, 2)
     p2 = Point(3, 4)
     p3 = Point(5, 7)
     assert not geometry.colinear(p1, p2, p3)
コード例 #29
0
 def test_2():
     p1 = Point(1, 0)
     p2 = Point(2, 0)
     p3 = Point(3, 0)
     assert geometry.colinear(p1, p2, p3)
コード例 #30
0
    def test_0():
        p1 = Point(1, 2)
        p2 = Point(3, 4)

        p = geometry.section(p1, p2, 0.5)
        assert p == Point(2, 3)