Exemplo n.º 1
0
def test_distance_point():
    print('plane-pt')
    pt = Point(0, 0, 0)
    pt1 = Point(0, 0, 1)
    pt2 = Point(1, 0, 1)
    pt3 = Point(1, 1, 1)
    plane = Plane(pt_1=pt1, pt_2=pt2, pt_3=pt3)
    print(plane.distance_to_point(pt))
Exemplo n.º 2
0
def test_distance_segment():
    print('plane-seg')
    pt1 = Point(0, 0, 1)
    pt2 = Point(1, 0, 1)
    pt3 = Point(1, 1, 1)
    pt4 = Point(0, 0, 0)
    pt5 = Point(1, 1, 0)
    pt6 = Point(0, 0, 2)
    seg1 = Segment(pt_1=pt4, pt_2=pt5)
    seg2 = Segment(pt_1=pt4, pt_2=pt6)
    plane = Plane(pt_1=pt1, pt_2=pt2, pt_3=pt3)
    print(plane.distance_to_segment(seg1)) # should be 1
    print(plane.distance_to_segment(seg2)) # they intersect
Exemplo n.º 3
0
def test_distance_line():
    print('plane-line')
    pt1 = Point(0, 0, 1)
    pt2 = Point(1, 0, 1)
    pt3 = Point(1, 1, 1)
    pt4 = Point(0, 0, 0)
    pt5 = Point(1, 1, 0)
    pt6 = Point(0, 1, 1)
    line1 = Line(pt_1=pt4, pt_2=pt5)
    line2 = Line(pt_1=pt4, pt_2=pt6)
    plane = Plane(pt_1=pt1, pt_2=pt2, pt_3=pt3)
    print(plane.distance_to_line(line1)) # should be 1
    print(plane.distance_to_line(line2)) # they intersect
Exemplo n.º 4
0
def test_distance_plane():
    print('poly-plane')
    pt1 = Point(-1, 1, 1)
    pt2 = Point(-1, 0, 1)
    pt3 = Point(1, 0, 1)
    pt4 = Point(0, 1, 2)
    pt5 = Point(0, 0, 2)
    pt6 = Point(1, 0, 2)
    pt7 = Point(-1, 0, -2)
    poly = PolygonRegular(vertices=[pt1, pt2, pt3])
    plane1 = Plane(pt_1=pt4, pt_2=pt5, pt_3=pt6)
    plane2 = Plane(pt_1=pt4, pt_2=pt5, pt_3=pt7)
    print(poly.distance_to_plane(plane1))  # should be 1
    print(poly.distance_to_plane(plane2))  # they intersect
Exemplo n.º 5
0
def test_distance_polygon():
    print('plane-poly')
    pt1 = Point(0, 0, 1)
    pt2 = Point(1, 0, 1)
    pt3 = Point(1, 1, 1)
    pt4 = Point(0, 0, 3)
    pt5 = Point(1, 0, 3)
    pt6 = Point(1, 1, 3)
    pt7 = Point(0, 0, -3)
    pt8 = Point(1, 0, 3)
    pt9 = Point(1, 1, 3)
    plane = Plane(pt_1=pt1, pt_2=pt2, pt_3=pt3)
    poly1 = PolygonRegular(vertices=[pt4, pt5, pt6])
    poly2 = PolygonRegular(vertices=[pt7, pt8, pt9])
    print(plane.distance_to_polygon(poly1)) # should be 2
    print(plane.distance_to_polygon(poly2)) # they intersect
Exemplo n.º 6
0
def test_distance_plane():
    print('plane-plane')
    pt1 = Point(0, 0, 1)
    pt2 = Point(1, 0, 1)
    pt3 = Point(1, 1, 1)
    pt4 = Point(0, 0, 3)
    pt5 = Point(1, 0, 3)
    pt6 = Point(1, 1, 3)
    pt7 = Point(0, 0, 2)
    pt8 = Point(1, 0, 3)
    pt9 = Point(1, 1, 3)
    plane1 = Plane(pt_1=pt1, pt_2=pt2, pt_3=pt3)
    plane2 = Plane(pt_1=pt4, pt_2=pt5, pt_3=pt6)
    plane3 = Plane(pt_1=pt7, pt_2=pt8, pt_3=pt9)
    print(plane1.distance_to_plane(plane2)) # should be 2
    print(plane1.distance_to_plane(plane3)) # they intersect
Exemplo n.º 7
0
def test_distance_plane():
    print('pt-plane')
    pt0 = Point(1, 1, 1)
    pt1 = Point(-1, 1, 0)
    pt2 = Point(1, 1, 0)
    pt3 = Point(0, 0, 0)
    print(pt0.distance_to_plane(Plane(pt_1=pt1, pt_2=pt2, pt_3=pt3)))
Exemplo n.º 8
0
def test_distance_plane():
    pt0 = Point(0, 0, 0)
    pt1 = Point(0, 0, 1)
    pt2 = Point(0, 1, 0)
    pt3 = Point(1, 0, 0)
    pt4 = Point(1, 0, 1)
    pt5 = Point(-1, 0, 10)
    plane = Plane(pt_1=pt0, pt_2=pt1, pt_3=pt2)
    line1 = Line(pt_1=pt3, pt_2=pt4)
    line2 = Line(pt_1=pt3, pt_2=pt5)
    print(line1.distance_to_plane(plane))  # should be 1
    print(line2.distance_to_plane(plane))  # they intersect
Exemplo n.º 9
0
def test_distance_line():
    pt0 = Point(0, 0, 0)
    pt1 = Point(1, 0, 0)
    pt2 = Point(1, 1, 0)
    pt3 = Point(0, 0, 4)
    line = Line(pt_1=pt1, pt_2=pt2)
    print('pt-line')
    print(pt0.distance_to_line(line))
    seg = Segment(pt1, pt2)
    print(pt0.distance_to_segment(seg))
    plane = Plane(pt_1=pt0, pt_2=pt1, pt_3=pt2)
    print(pt3.distance_to_plane(plane))
Exemplo n.º 10
0
def test_distance_plane():
    pt1 = Point(0, 0, 1)
    pt2 = Point(0, 0, -1)
    pt3 = Point(0, 1, 1)
    pt4 = Point(-1, 0, 0)
    pt5 = Point(1, 0, 0)
    pt6 = Point(-1, 0, 1)
    plane = Plane(pt_1=pt1, pt_2=pt2, pt_3=pt3)
    seg1 = Segment(pt_1=pt4, pt_2=pt5)
    seg2 = Segment(pt_1=pt4, pt_2=pt6)
    print(seg1.distance_to_plane(plane))  # they cross
    print(seg2.distance_to_plane(plane))  # distance should be 1
Exemplo n.º 11
0
def test_distance_prism():
    print('plane-prism')
    pt1 = Point(0, 0, 1)
    pt2 = Point(1, 0, 1)
    pt3 = Point(1, 1, 1)
    pt4 = Point(0, 0, 3)
    pt5 = Point(1, 0, 3)
    pt6 = Point(1, 1, 3)
    pt7 = Point(0, 0, -3)
    pt8 = Point(1, 0, -3)
    pt9 = Point(1, 1, -3)
    pt10 = Point(0, 0, 5)
    pt11 = Point(0, 1, 5)
    pt12 = Point(1, 1, 5)
    plane = Plane(pt_1=pt1, pt_2=pt2, pt_3=pt3)
    top_facet = PolygonRegular(vertices=[pt4, pt5, pt6])
    bot_facet = PolygonRegular(vertices=[pt7, pt8, pt9])
    bot_facet2 = PolygonRegular(vertices=[pt10, pt11, pt12])
    prism1 = PrismRegular(top_facet, bot_facet)
    prism2 = PrismRegular(top_facet, bot_facet2)
    print(plane.distance_to_prism(prism1)) # they intersect
    print(plane.distance_to_prism(prism2)) # should be 2
Exemplo n.º 12
0
 def init_vertices(self, vertices):
     if len(vertices) < 3:
         print('error in poly init_vertices:', 'not enough vertices number')
         return None
     self.vertices = vertices
     x = 0
     y = 0
     z = 0
     for pt in self.vertices:
         x += pt.x
         y += pt.y
         z += pt.z
     self.N = len(self.vertices)
     self.central_angle = math.pi / self.N
     # TODO: center is useful, but imports are recursive if uncomment next line
     self.center = Point(x / self.N, y / self.N, z / self.N)
     self.edge_length = self.vertices[-1].distance_to_point(
         self.vertices[0])
     self.outer_radius = self.edge_length / 2 / math.sin(self.central_angle)
     self.inner_radius = (self.outer_radius**2 -
                          self.edge_length**2 / 4)**0.5
     self.containing_plane = Plane(pt_1=self.vertices[0],
                                   pt_2=self.vertices[1],
                                   pt_3=self.vertices[2])
Exemplo n.º 13
0
def test_inits():
    print('pt...')
    pt = Point(0, 0, 0)
    print('pt ok')

    print('vec...')
    vec = Vector(1, 1, 1)
    print('vec ok')

    print('m2...')
    m21 = Matrix2(a11=0, a12=0, a21=0, a22=0)
    print('1 ok')
    m22 = Matrix2(elements=[0, 0, 0, 0])
    print('2 ok')
    print('m2 ok')

    print('m3...')
    m31 = Matrix3(a11=0,
                  a12=0,
                  a13=0,
                  a21=0,
                  a22=0,
                  a23=0,
                  a31=0,
                  a32=0,
                  a33=0)
    print('1 ok')
    m32 = Matrix3(elements=[0, 0, 0, 0, 0, 0, 0, 0, 0])
    print('2 ok')
    print('m3 ok')

    print('m4...')
    m41 = Matrix4(a11=0,
                  a12=0,
                  a13=0,
                  a14=0,
                  a21=0,
                  a22=0,
                  a23=0,
                  a24=0,
                  a31=0,
                  a32=0,
                  a33=0,
                  a34=0,
                  a41=0,
                  a42=0,
                  a43=0,
                  a44=0)
    print('1 ok')
    m42 = Matrix4(elements=[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0])
    print('2 ok')
    print('m4 ok')

    print('line...')
    line1 = Line(pt_1=Point(0, 0, 0), pt_2=Point(1, 1, 1))
    print('1 ok')
    #line2 = Line(plane_1=None, plane_2=None)
    print('line ok')

    print('seg')
    segment = Segment(beg=Point(0, 0, 0), end=Point(1, 1, 1))
    print('seg ok')

    print('plane')
    plane1 = Plane(a=1, b=1, c=1, d=1)
    print('1 ok')
    plane2 = Plane(pt_1=Point(0, 0, 0),
                   pt_2=Point(0, 0, 1),
                   pt_3=Point(0, 1, 0))
    print('2 ok')
    plane3 = Plane(pt=Point(0, 0, 0), normal=Vector(1, 1, 1))
    print('3 ok')
    plane4 = Plane(pt=Point(0, 0, 0),
                   segment=Segment(beg=Point(0, 0, 1), end=Point(1, 1, 1)))
    print('4 ok')
    print('plane ok')

    print('poly_reg')
    polygon_reg1 = PolygonRegular(vertices=(Point(0, 0, 0), Point(1, 0, 0),
                                            Point(0, 1, 0), Point(1, 1, 0)))
    print('poly_reg ok')

    print('prism_reg')
    prism_reg1 = PrismRegular(
        top_facet=polygon_reg1,
        bot_facet=PolygonRegular(vertices=(Point(0, 0, 1), Point(1, 0, 1),
                                           Point(0, 1, 1), Point(1, 1, 1))))
    print('prism_reg ok')