def test_average_points_dist(): p0 = Point(0.0, 0.0, 0.0, 3.0, 1) p1 = Point(0.0, 0.0, 1.0, 3.0, 1) p2 = Point(0.0, 1.0, 0.0, 3.0, 1) p3 = Point(1.0, 0.0, 0.0, 3.0, 1) av_dist = average_points_dist(p0, [p1, p2, p3]) nt.ok_(av_dist == 1.0)
def test_path_distance(): p1 = Point(3.0, 4.0, 5.0, 3.0, 1) p2 = Point(3.0, 5.0, 5.0, 3.0, 1) p3 = Point(3.0, 6.0, 5.0, 3.0, 1) p4 = Point(3.0, 7.0, 5.0, 3.0, 1) p5 = Point(3.0, 8.0, 5.0, 3.0, 1) dist = path_distance([p1, p2, p3, p4, p5]) nt.ok_(dist == 4)
def test_polygon_diameter(): p1 = Point(3.0, 4.0, 5.0, 3.0, 1) p2 = Point(3.0, 5.0, 5.0, 3.0, 1) p3 = Point(3.0, 6.0, 5.0, 3.0, 1) dia= polygon_diameter([p1,p2,p3]) nt.ok_(dia==2.0) surfpoint= soma_points() dia1 = polygon_diameter(surfpoint) nt.ok_(fabs(dia1-10.0) < 0.1)
def test_point_members(): p = Point(1, 2, 3, 4, 'FOO') nt.ok_(p.t == 'FOO') nt.ok_(p.x == 1) nt.ok_(p.y == 2) nt.ok_(p.z == 3) nt.ok_(p.r == 4)
def soma_points(radius=5,number_points=20): phi = uniform(0, 2*pi, number_points) costheta = uniform(-1,1, number_points) theta = np.arccos(costheta) x = radius*np.sin(theta)*np.cos(phi) y = radius*np.sin(theta)*np.sin(phi) z = radius*np.cos(theta) return [Point(i, j, k, 0.0, 1) for (i, j, k) in zip(x, y, z)]
def test_segment_volume(): p0 = Point(0.0, 0.0, 0.0, 3.0, 1) p1 = Point(2.0, 0.0, 0.0, 3.0, 1) p2 = Point(4.0, 0.0, 0.0, 3.0, 1) p3 = Point(4.0, 0.0, 0.0, 6.0, 1) p4 = Point(1.0, 0.0, 0.0, 3.0, 1) p5 = Point(4.0, 0.0, 0.0, 3.0, 1) v01 = segment_volume((p0, p1)) v02 = segment_volume((p0, p2)) v03 = segment_volume((p0, p3)) v04 = segment_volume((p0, p4)) v45 = segment_volume((p4, p5)) v05 = segment_volume((p0, p5)) nt.assert_almost_equal(v01, 56.5486677, places=6) nt.assert_almost_equal(2*v01, v02) nt.assert_almost_equal(v03, 263.8937829, places=6) nt.assert_almost_equal(v45, v05 - v04) nt.assert_almost_equal(segment_volume((p0, p3)), segment_volume((p3, p0)))
def test_segment_area(): p0 = Point(0.0, 0.0, 0.0, 3.0, 1) p1 = Point(2.0, 0.0, 0.0, 3.0, 1) p2 = Point(4.0, 0.0, 0.0, 3.0, 1) p3 = Point(4.0, 0.0, 0.0, 6.0, 1) p4 = Point(1.0, 0.0, 0.0, 3.0, 1) p5 = Point(4.0, 0.0, 0.0, 3.0, 1) a01 = segment_area((p0, p1)) a02 = segment_area((p0, p2)) a03 = segment_area((p0, p3)) a04 = segment_area((p0, p4)) a45 = segment_area((p4, p5)) a05 = segment_area((p0, p5)) nt.assert_almost_equal(a01, 37.6991118, places=6) nt.assert_almost_equal(2*a01, a02) nt.assert_almost_equal(a03, 141.3716694, places=6) nt.assert_almost_equal(a45, a05 - a04) nt.assert_almost_equal(segment_area((p0, p3)), segment_area((p3, p0)))
def test_point_dist(): p1 = Point(3.0, 4.0, 5.0, 3.0, 1) p2 = Point(4.0, 5.0, 6.0, 3.0, 1) dist = point_dist(p1,p2) nt.ok_(dist==sqrt(3))
def test_point_dist(): p1 = Point(3.0, 4.0, 5.0, 3.0, 1) p2 = Point(4.0, 5.0, 6.0, 3.0, 1) dist = mm.point_dist(p1,p2) nt.eq_(dist, sqrt(3))
def test_segment_length2(): p1 = Point(3.0, 4.0, 5.0, 3.0, 1) p2 = Point(4.0, 5.0, 6.0, 3.0, 1) dist = mm.segment_length2((p1, p2)) nt.eq_(dist, 3)