def _eval_subs(self, old, new): from sympy.geometry.point import Point, Point3D if is_sequence(old) or is_sequence(new): if isinstance(self, Point3D): old = Point3D(old) new = Point3D(new) else: old = Point(old) new = Point(new) return self._subs(old, new)
def test_deviation(): n1, n2 = symbols('n1, n2') r1 = Ray3D(Point3D(-1, -1, 1), Point3D(0, 0, 0)) n = Matrix([0, 0, 1]) i = Matrix([-1, -1, -1]) normal_ray = Ray3D(Point3D(0, 0, 0), Point3D(0, 0, 1)) P = Plane(Point3D(0, 0, 0), normal_vector=[0, 0, 1]) assert deviation(r1, 1, 1, normal=n) == 0 assert deviation(r1, 1, 1, plane=P) == 0 assert deviation(r1, 1, 1.1, plane=P).evalf(3) + 0.119 < 1e-3 assert deviation(i, 1, 1.1, normal=normal_ray).evalf(3) + 0.119 < 1e-3 assert deviation(r1, 1.33, 1, plane=P) is None # TIR assert deviation(r1, 1, 1, normal=[0, 0, 1]) == 0 assert deviation([-1, -1, -1], 1, 1, normal=[0, 0, 1]) == 0
def are_coplanar(*e): """ Returns True if the given entities are coplanar otherwise False Parameters ========== e: entities to be checked for being coplanar Returns ======= Boolean Examples ======== >>> from sympy import Point3D, Line3D >>> from sympy.geometry.util import are_coplanar >>> a = Line3D(Point3D(5, 0, 0), Point3D(1, -1, 1)) >>> b = Line3D(Point3D(0, -2, 0), Point3D(3, 1, 1)) >>> c = Line3D(Point3D(0, -1, 0), Point3D(5, -1, 9)) >>> are_coplanar(a, b, c) False """ from sympy.geometry.line import LinearEntity3D from sympy.geometry.entity import GeometryEntity from sympy.geometry.point import Point3D from sympy.geometry.plane import Plane # XXX update tests for coverage e = set(e) # first work with a Plane if present for i in list(e): if isinstance(i, Plane): e.remove(i) return all(p.is_coplanar(i) for p in e) if all(isinstance(i, Point3D) for i in e): if len(e) < 3: return False # remove pts that are collinear with 2 pts a, b = e.pop(), e.pop() for i in list(e): if Point3D.are_collinear(a, b, i): e.remove(i) if not e: return False else: # define a plane p = Plane(a, b, e.pop()) for i in e: if i not in p: return False return True else: pt3d = [] for i in e: if isinstance(i, Point3D): pt3d.append(i) elif isinstance(i, LinearEntity3D): pt3d.extend(i.args) elif isinstance( i, GeometryEntity ): # XXX we should have a GeometryEntity3D class so we can tell the difference between 2D and 3D -- here we just want to deal with 2D objects; if new 3D objects are encountered that we didn't handle above, an error should be raised # all 2D objects have some Point that defines them; so convert those points to 3D pts by making z=0 for p in i.args: if isinstance(p, Point): pt3d.append(Point3D(*(p.args + (0, )))) return are_coplanar(*pt3d)
def are_coplanar(*e): """ Returns True if the given entities are coplanar otherwise False Parameters ========== e: entities to be checked for being coplanar Returns ======= Boolean Examples ======== >>> from sympy import Point3D, Line3D >>> from sympy.geometry.util import are_coplanar >>> a = Line3D(Point3D(5, 0, 0), Point3D(1, -1, 1)) >>> b = Line3D(Point3D(0, -2, 0), Point3D(3, 1, 1)) >>> c = Line3D(Point3D(0, -1, 0), Point3D(5, -1, 9)) >>> are_coplanar(a, b, c) False """ from sympy.geometry.line import LinearEntity3D from sympy.geometry.point import Point3D from sympy.geometry.plane import Plane # XXX update tests for coverage e = set(e) # first work with a Plane if present for i in list(e): if isinstance(i, Plane): e.remove(i) return all(p.is_coplanar(i) for p in e) if all(isinstance(i, Point3D) for i in e): if len(e) < 3: return False # remove pts that are collinear with 2 pts a, b = e.pop(), e.pop() for i in list(e): if Point3D.are_collinear(a, b, i): e.remove(i) if not e: return False else: # define a plane p = Plane(a, b, e.pop()) for i in e: if i not in p: return False return True else: pt3d = [] for i in e: if isinstance(i, Point3D): pt3d.append(i) elif isinstance(i, LinearEntity3D): pt3d.extend(i.args) elif isinstance(i, GeometryEntity): # XXX we should have a GeometryEntity3D class so we can tell the difference between 2D and 3D -- here we just want to deal with 2D objects; if new 3D objects are encountered that we didn't hanlde above, an error should be raised # all 2D objects have some Point that defines them; so convert those points to 3D pts by making z=0 for p in i.args: if isinstance(p, Point): pt3d.append(Point3D(*(p.args + (0,)))) return are_coplanar(*pt3d)
def test_refraction_angle(): n1, n2 = symbols('n1, n2') m1 = Medium('m1') m2 = Medium('m2') r1 = Ray3D(Point3D(-1, -1, 1), Point3D(0, 0, 0)) i = Matrix([1, 1, 1]) n = Matrix([0, 0, 1]) normal_ray = Ray3D(Point3D(0, 0, 0), Point3D(0, 0, 1)) P = Plane(Point3D(0, 0, 0), normal_vector=[0, 0, 1]) assert refraction_angle(r1, 1, 1, n) == Matrix([[1], [1], [-1]]) assert refraction_angle([1, 1, 1], 1, 1, n) == Matrix([[1], [1], [-1]]) assert refraction_angle((1, 1, 1), 1, 1, n) == Matrix([[1], [1], [-1]]) assert refraction_angle(i, 1, 1, [0, 0, 1]) == Matrix([[1], [1], [-1]]) assert refraction_angle(i, 1, 1, (0, 0, 1)) == Matrix([[1], [1], [-1]]) assert refraction_angle(i, 1, 1, normal_ray) == Matrix([[1], [1], [-1]]) assert refraction_angle(i, 1, 1, plane=P) == Matrix([[1], [1], [-1]]) assert refraction_angle(r1, 1, 1, plane=P) == \ Ray3D(Point3D(0, 0, 0), Point3D(1, 1, -1)) assert refraction_angle(r1, m1, 1.33, plane=P) == \ Ray3D(Point3D(0, 0, 0), Point3D(100/133, 100/133, -789378201649271*sqrt(3)/1000000000000000)) assert refraction_angle(r1, 1, m2, plane=P) == \ Ray3D(Point3D(0, 0, 0), Point3D(1, 1, -1)) assert refraction_angle(r1, n1, n2, plane=P) == \ Ray3D(Point3D(0, 0, 0), Point3D(n1/n2, n1/n2, -sqrt(3)*sqrt(-2*n1**2/(3*n2**2) + 1))) assert refraction_angle(r1, 1.33, 1, plane=P) == 0 # TIR assert refraction_angle(r1, 1, 1, normal_ray) == \ Ray3D(Point3D(0, 0, 0), direction_ratio=[1, 1, -1])
def test_refraction_angle(): n1, n2 = symbols('n1, n2') m1 = Medium('m1') m2 = Medium('m2') r1 = Ray3D(Point3D(-1, -1, 1), Point3D(0, 0, 0)) i = Matrix([1, 1, 1]) n = Matrix([0, 0, 1]) normal_ray = Ray3D(Point3D(0, 0, 0), Point3D(0, 0, 1)) P = Plane(Point3D(0, 0, 0), normal_vector=[0, 0, 1]) assert refraction_angle(r1, 1, 1, n) == Matrix([[1], [1], [-1]]) assert refraction_angle([1, 1, 1], 1, 1, n) == Matrix([[1], [1], [-1]]) assert refraction_angle((1, 1, 1), 1, 1, n) == Matrix([[1], [1], [-1]]) assert refraction_angle(i, 1, 1, [0, 0, 1]) == Matrix([[1], [1], [-1]]) assert refraction_angle(i, 1, 1, (0, 0, 1)) == Matrix([[1], [1], [-1]]) assert refraction_angle(i, 1, 1, normal_ray) == Matrix([[1], [1], [-1]]) assert refraction_angle(i, 1, 1, plane=P) == Matrix([[1], [1], [-1]]) assert refraction_angle(r1, 1, 1, plane=P) == \ Ray3D(Point3D(0, 0, 0), Point3D(1, 1, -1)) assert refraction_angle(r1, m1, 1.33, plane=P) == \ Ray3D(Point3D(0, 0, 0), Point3D(Rational(100, 133), Rational(100, 133), -789378201649271*sqrt(3)/1000000000000000)) assert refraction_angle(r1, 1, m2, plane=P) == \ Ray3D(Point3D(0, 0, 0), Point3D(1, 1, -1)) assert refraction_angle(r1, n1, n2, plane=P) == \ Ray3D(Point3D(0, 0, 0), Point3D(n1/n2, n1/n2, -sqrt(3)*sqrt(-2*n1**2/(3*n2**2) + 1))) assert refraction_angle(r1, 1.33, 1, plane=P) == 0 # TIR assert refraction_angle(r1, 1, 1, normal_ray) == \ Ray3D(Point3D(0, 0, 0), direction_ratio=[1, 1, -1]) assert ae(refraction_angle(0.5, 1, 2), 0.24207, 5) assert ae(refraction_angle(0.5, 2, 1), 1.28293, 5) raises(ValueError, lambda: refraction_angle(r1, m1, m2, normal_ray, P)) raises(TypeError, lambda: refraction_angle(m1, m1, m2) ) # can add other values for arg[0] raises(TypeError, lambda: refraction_angle(r1, m1, m2, None, i)) raises(TypeError, lambda: refraction_angle(r1, m1, m2, m2))
if (DISPLAY): p.add_point_labels(posterior_point, [ "Post Point"], point_color='white', point_size=20) p.add_point_labels( anterior_point, ["Ant Point"], point_color='red', point_size=20) p.add_legend() p.add_axes() p.show() raise # Check if point is lateral or medial # posterior_point_distance = posterior_point_distance = sagittal_plane.distance( Point3D(posterior_point, evaluate=False)) if (posterior_point_distance < 0): # Find sagittale plane initial_sagitall_axis = np.array([1, 0, 0]) initial_sagitall_plane = Plane( femur_cm, normal_vector=initial_sagitall_axis) max_distance = -100000 for idx, point in enumerate(femur_3D_points): d = initial_sagitall_plane.distance(point) if (d > max_distance): max_distance = d index_point_max_sagitall_distance = idx else: initial_sagitall_axis = np.array([1, 0, 0]) initial_sagitall_plane = Plane(