def test_path_fraction_many_points(): def x(theta): return np.cos(theta) def y(theta): return np.sin(theta) points = [ np.array((x(theta), y(theta), 2.)) for theta in (0., np.pi / 4., np.pi / 2., 3. * np.pi / 4., np.pi) ] res = mm.path_fraction_point(points, 0.) nt.assert_true(np.allclose(res, (x(0.), y(0.), 2.))) res = mm.path_fraction_point(points, 0.25) nt.assert_true(np.allclose(res, (x(np.pi / 4.), y(np.pi / 4.), 2.))) res = mm.path_fraction_point(points, 0.5) nt.assert_true(np.allclose(res, (x(np.pi / 2.), y(np.pi / 2.), 2.))) res = mm.path_fraction_point(points, 0.75) nt.assert_true( np.allclose(res, (x(3. * np.pi / 4.), y(3. * np.pi / 4.), 2.))) res = mm.path_fraction_point(points, 1.) nt.assert_true(np.allclose(res, (x(np.pi), y(np.pi), 2.)))
def test_path_fraction_point_two_points(): points = [np.array([-1., -1., -1.]), np.array([1., 1., 1.])] res = mm.path_fraction_point(points, 0.0) assert np.allclose(res, (-1., -1., -1.)) res = mm.path_fraction_point(points, 0.25) assert np.allclose(res, (-0.5, -0.5, -0.5)) res = mm.path_fraction_point(points, 1.0) assert np.allclose(res, (1., 1., 1.))
def test_path_fraction_point_two_points(): points = [np.array([-1.,-1.,-1.]), np.array([1.,1.,1.])] res = mm.path_fraction_point(points, 0.0) nt.assert_true(np.allclose(res, (-1.,-1.,-1.))) res = mm.path_fraction_point(points, 0.25) nt.assert_true(np.allclose(res, (-0.5,-0.5,-0.5))) res = mm.path_fraction_point(points, 1.0) nt.assert_true(np.allclose(res, (1.,1.,1.)))
def test_path_fraction_many_points(): x = lambda theta: np.cos(theta) y = lambda theta: np.sin(theta) points = [np.array((x(theta), y(theta), 2.)) for theta in (0., np.pi/4., np.pi/2., 3.*np.pi/4., np.pi)] res = mm.path_fraction_point(points, 0.) nt.assert_true(np.allclose(res, (x(0.), y(0.), 2.))) res = mm.path_fraction_point(points, 0.25) nt.assert_true(np.allclose(res, (x(np.pi/4.), y(np.pi/4.), 2.))) res = mm.path_fraction_point(points, 0.5) nt.assert_true(np.allclose(res, (x(np.pi/2.), y(np.pi/2.), 2.))) res = mm.path_fraction_point(points, 0.75) nt.assert_true(np.allclose(res, (x(3.*np.pi/4.), y(3.*np.pi/4.), 2.))) res = mm.path_fraction_point(points, 1.) nt.assert_true(np.allclose(res, (x(np.pi), y(np.pi), 2.)))
def test_path_fraction_three_symmetric_points(): points = [np.array((1., 0., 0.)), np.array((0., 0., 0.)), np.array((0., 0., 1.))] res = mm.path_fraction_point(points, 0.0) assert np.allclose(res, (1., 0., 0.)) res = mm.path_fraction_point(points, 0.25) assert np.allclose(res, (0.5, 0., 0.)) res = mm.path_fraction_point(points, 0.5) assert np.allclose(res, (0., 0., 0.)) res = mm.path_fraction_point(points, 0.75) assert np.allclose(res, (0., 0., 0.5)) res = mm.path_fraction_point(points, 1.0) assert np.allclose(res, (0., 0., 1.))
def test_path_fraction_three_symmetric_points(): points = [np.array((1., 0., 0.)), np.array((0., 0., 0.)), np.array((0., 0., 1.))] res = mm.path_fraction_point(points, 0.0) nt.assert_true(np.allclose(res, (1., 0., 0.))) res = mm.path_fraction_point(points, 0.25) nt.assert_true(np.allclose(res, (0.5, 0., 0.))) res = mm.path_fraction_point(points, 0.5) nt.assert_true(np.allclose(res, (0., 0., 0.))) res = mm.path_fraction_point(points, 0.75) nt.assert_true(np.allclose(res, (0., 0., 0.5))) res = mm.path_fraction_point(points, 1.0) nt.assert_true(np.allclose(res, (0., 0., 1.)))
def point_at_path_fraction(section, fraction): '''Computes the point which corresponds to the fraction of the path length along the piecewise linear curve which is constructed from the section points. Args: 0, 1, 2 correspoding to 3D cartesian coordinates Returns: The 3D coordinates of the aforementioned point ''' return mm.path_fraction_point(tuple(n.value for n in section), fraction)