Coverage for pygeodesy/vector3d.py : 94%

Hot-keys on this page
r m x p toggle line displays
j k next/prev highlighted chunk
0 (zero) top of page
1 (one) first highlighted chunk
# -*- coding: utf-8 -*-
and functions L{intersections2}, L{iscolinearWith}, L{nearestOn}, L{parse3d}, L{sumOf} and L{trilaterate3d2}.
Pure Python implementation of vector-based functions by I{(C) Chris Veness 2011-2015} published under the same MIT Licence**, see U{Vector-based geodesy <https://www.Movable-Type.co.UK/scripts/latlong-vectors.html>}.
@newfield example: Example, Examples '''
property_RO, _xnumpy, _xkwds _IsnotError, _TypeError, _ValueError _COMMA_, _COMMA_SPACE_, _datum_, _h_, _height_, \ _invalid_, joined_, _Missing, _name_, \ _near_concentric_, _no_intersection_, _PARENTH_, \ _scalar_, _too_distant_fmt_, _y_, _z_, _0_0, _1_0
'''(INTERNAL) Get an C{(x, y, z, name)} 4-tuple. ''' except (TypeError, ValueError) as x: d = dict(zip(('xyz', _y_, _z_), t)) raise Error(txt=str(x), **d)
'''(INTERNAL) Get an C{(x, y, z, h, d, name)} 6-tuple. '''
or getattr(xyz, _h_, None) \ or getattr(ll, _height_, None)
or getattr(ll, _datum_, None)
'''L{Vector3d} or C{*Nvector} issue. '''
'''Generic 3-D vector manipulation.
In a geodesy context, these may be used to represent: - n-vector representing a normal to point on earth's surface - earth-centered, earth-fixed vector (= n-vector for spherical model) - great circle normal to vector - motion vector on earth's surface - etc. '''
'''New 3-D L{Vector3d}.
The vector may be normalised or use x/y/z values for height relative to the surface of the sphere or ellipsoid, distance from earth centre, etc.
@arg x: X component of vector (C{scalar}). @arg y: Y component of vector (C{scalar}). @arg z: Z component of vector (C{scalar}). @kwarg ll: Optional latlon reference (C{LatLon}). @kwarg name: Optional name (C{str}). '''
'''Return the norm of this vector.
@return: Norm, unit length (C{float}); ''' return self.length
'''Add this to an other vector (L{Vector3d}).
@return: Vectorial sum (L{Vector3d}).
@raise TypeError: Incompatible B{C{other}} C{type}. ''' # __iadd__ = __add__
'''Compare this and an other vector
@arg other: The other vector (L{Vector3d}).
@return: -1, 0 or +1 (C{int}).
@raise TypeError: Incompatible B{C{other}} C{type}. ''' +1 if self.length > other.length else 0)
'''Divide this vector by a scalar.
@arg scalar: The divisor (C{scalar}).
@return: Quotient (L{Vector3d}).
@raise TypeError: Non-scalar B{C{scalar}}. ''' # __itruediv__ = __div__
'''Is this vector equal to an other vector?
@arg other: The other vector (L{Vector3d}).
@return: C{True} if equal, C{False} otherwise.
@raise TypeError: Incompatible B{C{other}} C{type}. '''
'''Is this vector longer than or equal to an other vector?
@arg other: The other vector (L{Vector3d}).
@return: C{True} if so, C{False} otherwise.
@raise TypeError: Incompatible B{C{other}} C{type}. '''
'''Is this vector longer than an other vector?
@arg other: The other vector (L{Vector3d}).
@return: C{True} if so, C{False} otherwise.
@raise TypeError: Incompatible B{C{other}} C{type}. '''
'''Is this vector shorter than or equal to an other vector?
@arg other: The other vector (L{Vector3d}).
@return: C{True} if so, C{False} otherwise.
@raise TypeError: Incompatible B{C{other}} C{type}. '''
'''Is this vector shorter than an other vector?
@arg other: The other vector (L{Vector3d}).
@return: C{True} if so, C{False} otherwise.
@raise TypeError: Incompatible B{C{other}} C{type}. '''
# Luciano Ramalho, "Fluent Python", page 397, O'Reilly 2016 '''Compute the cross product of this and an other vector.
@arg other: The other vector (L{Vector3d}).
@return: Cross product (L{Vector3d}).
@raise TypeError: Incompatible B{C{other}} C{type}. ''' # __imatmul__ = __matmul__
'''Multiply this vector by a scalar
@arg scalar: Factor (C{scalar}).
@return: Product (L{Vector3d}). ''' # __imul__ = __mul__ # __rmul__ = __mul__
'''Is this vector not equal to an other vector?
@arg other: The other vector (L{Vector3d}).
@return: C{True} if so, C{False} otherwise.
@raise TypeError: Incompatible B{C{other}} C{type}. '''
'''Negate this vector.
@return: Negative (L{Vector3d}) ''' return self.negate()
'''Copy this vector.
@return: Positive (L{Vector3d}) ''' return self.copy()
# Luciano Ramalho, "Fluent Python", page 397, O'Reilly 2016 '''Compute the cross product of an other and this vector.
@arg other: The other vector (L{Vector3d}).
@return: Cross product (L{Vector3d}).
@raise TypeError: Incompatible B{C{other}} C{type}. '''
'''Subtract this vector from an other vector.
@arg other: The other vector (L{Vector3d}).
@return: Difference (L{Vector3d}).
@raise TypeError: Incompatible B{C{other}} C{type}. ''' self.others(other) return other.minus(self)
'''Subtract an other vector from this vector.
@arg other: The other vector (L{Vector3d}).
@return: Difference (L{Vector3d}).
@raise TypeError: Incompatible B{C{other}} C{type}. ''' # __isub__ = __sub__
'''(INTERNAL) Zap cached attributes if updated. ''' '_length', '_length2', '_united', '_xyz', *attrs)
'''Compute the angle between this and an other vector.
@arg other: The other vector (L{Vector3d}). @kwarg vSign: Optional vector, if supplied (and out of the plane of this and the other), angle is signed positive if this->other is clockwise looking along vSign or negative in opposite direction, otherwise angle is unsigned. @kwarg warp: Wrap/unroll the angle to +/-PI (c{bool}).
@return: Angle (C{radians}).
@raise TypeError: If B{C{other}} or B{C{vSign}} not a L{Vector3d}. ''' # use vSign as reference to get sign of s
a -= copysign(PI2, a)
'''Compute the cross product of this and an other vector.
@arg other: The other vector (L{Vector3d}). @kwarg raiser: Optional, L{CrossError} label if raised (C{str}).
@return: Cross product (L{Vector3d}).
@raise CrossError: Zero or near-zero cross product and both B{C{raiser}} and L{crosserrors} set.
@raise TypeError: Incompatible B{C{other}} C{type}. '''
raise CrossError(raiser, r, txt=t)
'''Get L{CrossError} exceptions (C{bool}). '''
'''Raise L{CrossError} exceptions (C{bool}). '''
'''Divide this vector by a scalar.
@arg factor: The divisor (C{scalar}).
@return: New, scaled vector (L{Vector3d}).
@raise TypeError: Non-scalar B{C{factor}}.
@raise VectorError: Invalid or zero B{C{factor}}. ''' raise _IsnotError(_scalar_, factor=factor) raise VectorError(factor=factor, txt=str(x))
'''Compute the dot (scalar) product of this and an other vector.
@arg other: The other vector (L{Vector3d}).
@return: Dot product (C{float}).
@raise TypeError: Incompatible B{C{other}} C{type}. ''' d = self.length2 else:
def equals(self, other, units=False): # PYCHOK no cover '''DEPRECATED, use method C{isequalTo}. ''' return self.isequalTo(other, units=units)
'''Approximate the length (norm, magnitude) of this vector.
@see: Function L{euclid_} and properties C{length} and C{length2}. '''
'''Check whether this and two other points are colinear.
@arg point1: One point (L{Vector3d}, C{Vector3Tuple} or C{Vector4Tuple}). @arg point2: Another point (L{Vector3d}, C{Vector3Tuple} or C{Vector4Tuple}). @kwarg eps: Tolerance (C{scalar}), same units as C{x}, C{y}, and C{z}.
@return: C{True} if colinear, C{False} otherwise.
@raise TypeError: Invalid B{C{point1}} or B{C{point2}}.
@see: Method L{nearestOn}. ''' v = self if self.name else _otherV3d(this=self) return _iscolinearWith(v, point1, point2, eps=eps)
'''Check if this and an other vector are equal or equivalent.
@arg other: The other vector (L{Vector3d}). @kwarg units: Optionally, compare the normalized, unit version of both vectors. @kwarg eps: Tolerance (C{scalar}), same units as C{x}, C{y}, and C{z}.
@return: C{True} if vectors are identical, C{False} otherwise.
@raise TypeError: Incompatible B{C{other}} C{type}.
@example:
>>> v1 = Vector3d(52.205, 0.119) >>> v2 = Vector3d(52.205, 0.119) >>> e = v1.isequalTo(v2) # True '''
else:
'''Get the length (norm, magnitude) of this vector (C{float}).
@see: Properties C{length2} and C{euclid}. '''
'''Get the length I{squared} of this vector (C{float}).
@see: Property C{length}. '''
'''Subtract an other vector from this vector.
@arg other: The other vector (L{Vector3d}).
@return: New vector difference (L{Vector3d}).
@raise TypeError: Incompatible B{C{other}} C{type}. '''
self.y - other.y, self.z - other.z)
'''Locate the point between two points closest to this point.
@arg other1: Start point (L{Vector3d}). @arg other2: End point (L{Vector3d}). @kwarg within: If C{True} return the closest point between the given points, otherwise the closest point on the extended line through both points (C{bool}).
@return: Closest point (L{Vector3d}).
@raise TypeError: If B{C{other1}} or B{C{other2}} is not L{Vector3d}.
@see: Method L{sphericalTrigonometry.LatLon.nearestOn3} and U{3-D Point-Line distance<https://MathWorld.Wolfram.com/ Point-LineDistance3-Dimensional.html>}. ''' _V3d(other2) or _otherV3d(other2=other2), within=within)
'''Return this vector in opposite direction.
@return: New, opposite vector (L{Vector3d}). '''
'''(INTERNAL) Get the (C{nvectorBase._N_vector_}) '''
'''Refined class comparison.
@arg other: The other vector (L{Vector3d}). @kwarg name_other_up: Overriding C{name=other} and C{up=1} keyword arguments.
@return: The B{C{other}} if compatible.
@raise TypeError: Incompatible B{C{other}} C{type}. ''' _NamedBase.others(self, other, name=name, up=up + 1)
'''Parse an C{"x, y, z"} string to a similar L{Vector3d} instance.
@arg str3d: X, y and z string (C{str}), see function L{parse3d}. @kwarg sep: Optional separator (C{str}). @kwarg name: Optional instance name (C{str}), overriding this name.
@return: The similar instance (L{Vector3d}).
@raise VectorError: Invalid B{C{str3d}}. ''' name=name or self.name)
'''Add this vector and an other vector.
@arg other: The other vector (L{Vector3d}).
@return: Vectorial sum (L{Vector3d}).
@raise TypeError: Incompatible B{C{other}} C{type}. '''
self.y + other.y, self.z + other.z)
'''Rotate this vector around an axis by a specified angle.
See U{Rotation matrix from axis and angle <https://WikiPedia.org/wiki/Rotation_matrix#Rotation_matrix_from_axis_and_angle>} and U{Quaternion-derived rotation matrix <https://WikiPedia.org/wiki/Quaternions_and_spatial_rotation#Quaternion-derived_rotation_matrix>}.
@arg axis: The axis being rotated around (L{Vector3d}). @arg theta: The angle of rotation (C{radians}).
@return: New, rotated vector (L{Vector3d}).
@JSname: I{rotateAround}. '''
# multiply p by a quaternion-derived rotation matrix fdot(p, a.y * b.x + s.z, a.y * b.y + c, a.y * b.z - s.x), fdot(p, a.z * b.x - s.y, a.z * b.y + s.x, a.z * b.z + c))
def rotateAround(self, axis, theta): # PYCHOK no cover '''DEPRECATED, use method C{rotate}. ''' return self.rotate(axis, theta)
'''Multiply this vector by a scalar.
@arg factor: Scale factor (C{scalar}).
@return: New, scaled vector (L{Vector3d}).
@raise TypeError: Non-scalar B{C{factor}}. ''' raise _IsnotError(_scalar_, factor=factor) self.y * factor, self.z * factor)
def to2ab(self): # PYCHOK no cover '''DEPRECATED, use property C{Nvector.philam}.
@return: A L{PhiLam2Tuple}C{(phi, lam)}. ''' return n_xyz2philam(self.x, self.y, self.z)
def to2ll(self): # PYCHOK no cover '''DEPRECATED, use property C{Nvector.latlon}.
@return: A L{LatLon2Tuple}C{(lat, lon)}. ''' return n_xyz2latlon(self.x, self.y, self.z)
def to3xyz(self): # PYCHOK no cover '''DEPRECATED, use property C{xyz}.
@return: A L{Vector3Tuple}C{(x, y, z)}. ''' return self.xyz
'''Return a string representation of this vector.
@kwarg prec: Optional number of decimal places (C{int}). @kwarg fmt: Optional, enclosing format to use (C{str}). @kwarg sep: Optional separator between components (C{str}).
@return: Vector as "(x, y, z)" (C{str}). '''
'''Trilaterate this and two other spheres, each given as a (3d) center and radius.
@arg radius: Radius of this sphere (same C{units} as this C{x}, C{y} and C{z}). @arg center2: Center of the 2nd sphere (L{Vector3d}, C{Vector3Tuple} or C{Vector4Tuple}). @arg radius2: Radius of this sphere (same C{units} as this C{x}, C{y} and C{z}). @arg center3: Center of the 3rd sphere (L{Vector3d}, C{Vector3Tuple} or C{Vector4Tuple}). @arg radius3: Radius of the 3rd sphere (same C{units} as this C{x}, C{y} and C{z}). @kwarg eps: Tolerance (C{scalar}), same units as C{x}, C{y}, and C{z}.
@return: 2-Tuple with two trilaterated points, each an instance of this L{Vector3d} (sub-)class. Both points are the same instance if all three spheres intersect or abut in a single point.
@raise ImportError: Package C{numpy} not found, not installed or older than version 1.15.
@raise IntersectionError: No intersection, colinear or near concentric centers or trilateration failed some other way.
@raise TypeError: Invalid B{C{center2}} or B{C{center3}}.
@raise UnitError: Invalid B{C{radius}}, B{C{radius2}} or B{C{radius3}}.
@note: Package U{numpy<https://pypi.org/project/numpy>} is required, version 1.15 or later.
@see: Norrdine, A. U{I{An Algebraic Solution to the Multilateration Problem}<https://www.ResearchGate.net/publication/ 275027725_An_Algebraic_Solution_to_the_Multilateration_Problem>} and U{I{implementation}<https://www.ResearchGate.net/publication/ 288825016_Trilateration_Matlab_Code>}. ''' Radius_(radius, low=eps), center2, radius2, center3, radius3, eps=eps, Vector=self.classof) raise IntersectionError(center=self, radius=radius, center2=center2, radius2=radius2, center3=center3, radius3=radius3, txt=str(x))
'''Normalize this vector to unit length.
@kwarg ll: Optional, original location (C{LatLon}).
@return: Normalized vector (L{Vector3d}). ''' else:
'''Get the X component (C{float}). '''
'''Get the X, Y and Z components (L{Vector3Tuple}C{(x, y, z)}). '''
'''Get the Y component (C{float}). '''
'''Get the Z component (C{float}). '''
Vector=None, **Vector_kwds): '''Compute the intersection of two spheres or circles, each defined by a center point and a radius.
@arg center1: Center of the first sphere or circle (L{Vector3d}, C{Vector3Tuple} or C{Vector4Tuple}). @arg radius1: Radius of the first sphere or circle (same units as the B{C{center1}} coordinates). @arg center2: Center of the second sphere or circle (L{Vector3d}, C{Vector3Tuple} or C{Vector4Tuple}). @arg radius2: Radius of the second sphere or circle (same units as the B{C{center1}} and B{C{center2}} coordinates). @kwarg sphere: If C{True} compute the center and radius of the intersection of two spheres. If C{False}, ignore the C{z}-component and compute the intersection of two circles (C{bool}). @kwarg Vector: Class to return intersections (L{Vector3d} or C{Vector3Tuple}) or C{None} for L{Vector3d}. @kwarg Vector_kwds: Optional, additional B{C{Vector}} keyword arguments, ignored if C{B{Vector}=None}.
@return: If B{C{sphere}} is C{True}, a 2-Tuple of the C{center} and C{radius} of the intersection of the spheres. The C{radius} is C{0.0} for abutting spheres.
If B{C{sphere}} is C{False}, a 2-tuple of the intersection points of two circles. For abutting circles, both points are the same B{C{Vector}} instance.
@raise IntersectionError: Concentric, invalid or non-intersecting spheres or circles.
@raise UnitError: Invalid B{C{radius1}} or B{C{radius2}}.
@see: U{Sphere-Sphere<https://MathWorld.Wolfram.com/Sphere- SphereIntersection.html>} and U{circle-circle <https://MathWorld.Wolfram.com/Circle-CircleIntersection.html>} intersections. ''' center2, Radius_(radius2=radius2), sphere=sphere, Vector=Vector, **Vector_kwds) except (TypeError, ValueError) as x: raise IntersectionError(center1=center1, radius1=radius1, center2=center2, radius2=radius2, txt=str(x))
Vector=None, **Vector_kwds): # (INTERNAL) Intersect two spheres or circles, see L{intersections2} # above, separated to allow callers to embellish any exceptions
fdot(xy1, u.y, u.x, c1.y), _0_0)
raise ValueError(_near_concentric_)
# compute intersections with c1 at (0, 0) and c2 at (d, 0), like # <https://MathWorld.Wolfram.com/Circle-CircleIntersection.html> elif y < 0: raise ValueError(_invalid_) else: # abutting y = _0_0 t = d if too_d is None else too_d raise ValueError(_too_distant_fmt_ % (t,)) else: # abutting
c2 if x > EPS1 else c1.plus(u.times(x)))
else: # abutting circles
'''Check whether a point is colinear with two other points.
@arg point: The point (L{Vector3d}, C{Vector3Tuple} or C{Vector4Tuple}). @arg point1: Another point (L{Vector3d}, C{Vector3Tuple} or C{Vector4Tuple}). @arg point2: Another point (L{Vector3d}, C{Vector3Tuple} or C{Vector4Tuple}). @kwarg eps: Tolerance (C{scalar}), same units as C{x}, C{y} and C{z}.
@return: C{True} if colinear, C{False} otherwise.
@raise TypeError: Invalid B{C{point}}, B{C{point1}} or B{C{point2}}.
@see: Function L{nearestOn}. ''' point1, point2, eps=eps)
# (INTERNAL) Check colinear, see L{isColinear} above, # separated to allow callers to embellish any exceptions
Vector=None, **Vector_kwds): '''Locate the point between two points closest to a reference.
@arg point: Reference point (L{Vector3d}, C{Vector3Tuple} or C{Vector4Tuple}). @arg point1: Start point (L{Vector3d}, C{Vector3Tuple} or C{Vector4Tuple}). @arg point2: End point (L{Vector3d}, C{Vector3Tuple} or C{Vector4Tuple}). @kwarg within: If C{True} return the closest point between both given points, otherwise the closest point on the extended line through both points (C{bool}). @kwarg Vector: Class to return closest point (L{Vector3d} or C{Vector3Tuple}) or C{None} for L{Vector3d}. @kwarg Vector_kwds: Optional, additional B{C{Vector}} keyword arguments, ignored if C{B{Vector}=None}.
@return: Closest point (L{Vector3d} or C{Vector}).
@raise TypeError: Invalid B{C{point}}, B{C{point1}} or B{C{point2}}.
@see: Methods L{sphericalTrigonometry.LatLon.nearestOn3} and L{sphericalTrigonometry.LatLon.nearestOn3} U{3-D Point-Line distance<https://MathWorld.Wolfram.com/ Point-LineDistance3-Dimensional.html>}. ''' _V3d(point1) or _otherV3d(point1=point1), _V3d(point2) or _otherV3d(point2=point2), within=within)
# (INTERNAL) Get closest point, see L{nearestOn} above, # separated to allow callers to embellish any exceptions
else: p2 if (within and t > (_1_0 - eps)) else p1.plus(p21.times(t)))
# (INTERNAL) Return the nullspace and rank of matrix A # @see: <https://SciPy-Cookbook.ReadTheDocs.io/items/RankNullspace.html>, # <https://NumPy.org/doc/stable/reference/generated/numpy.linalg.svd.html>, # <https://StackOverflow.com/questions/19820921>, # <https://StackOverflow.com/questions/2992947> and # <https://StackOverflow.com/questions/5889142> raise _AssertionError(shape=m, txt=modulename(_null_space2, True)) # if needed, square A, pad with zeros # try: # no numpy.linalg.null_space <https://docs.SciPy.org/doc/> # return scipy.linalg.null_space(A) # XXX no scipy.linalg? # except AttributeError: # pass raise _AssertionError(shape=s, txt=modulename(_null_space2, True)) raise _AssertionError(eps=e, txt=modulename(_null_space2, True)) else: # coincident, colinear, concentric centers, ambiguous, etc. # del A, s, vh # release numpy
# check B{C{name#}} vector instance, return Vector3d except AttributeError: # no _x_ or _y_ attr pass raise _xotherError(Vector3d(0, 0, 0), v, name=name, up=2)
'''Parse an C{"x, y, z"} string.
@arg str3d: X, y and z values (C{str}). @kwarg sep: Optional separator (C{str}). @kwarg name: Optional instance name (C{str}). @kwarg Vector: Optional class (L{Vector3d}). @kwarg Vector_kwds: Optional B{C{Vector}} keyword arguments, ignored if C{B{Vector}=None}.
@return: New B{C{Vector}} or if B{C{Vector}} is C{None}, a L{Vector3Tuple}C{(x, y, z)}.
@raise VectorError: Invalid B{C{str3d}}. ''' raise _ValueError(len=n) except (TypeError, ValueError) as x: raise VectorError(str3d=str3d, txt=str(x))
'''Compute the vectorial sum of several vectors.
@arg vectors: Vectors to be added (L{Vector3d}[]). @kwarg Vector: Optional class for the vectorial sum (L{Vector3d}). @kwarg Vector_kwds: Optional B{C{Vector}} keyword arguments, ignored if C{B{Vector}=None}.
@return: Vectorial sum as B{C{Vector}} or if B{C{Vector}} is C{None}, a L{Vector3Tuple}C{(x, y, z)}.
@raise VectorError: No B{C{vectors}}. ''' raise VectorError(vectors=n, txt=_Missing)
fsum(v.y for v in vectors), fsum(v.z for v in vectors))
eps=EPS, Vector=None, **Vector_kwds): '''Trilaterate three spheres, each given as a (3d) center point and radius.
@arg center1: Center of the 1st sphere (L{Vector3d}, C{Vector3Tuple} or C{Vector4Tuple}). @arg radius1: Radius of the 1st sphere (same C{units} as C{x}, C{y} and C{z}). @arg center2: Center of the 2nd sphere (L{Vector3d}, C{Vector3Tuple} or C{Vector4Tuple}). @arg radius2: Radius of this sphere (same C{units} as C{x}, C{y} and C{z}). @arg center3: Center of the 3rd sphere (L{Vector3d}, C{Vector3Tuple} or C{Vector4Tuple}). @arg radius3: Radius of the 3rd sphere (same C{units} as C{x}, C{y} and C{z}). @kwarg eps: Tolerance (C{scalar}), same units as C{x}, C{y}, and C{z}. @kwarg Vector: Class to return intersections (L{Vector3d} or C{Vector3Tuple}) or C{None} for L{Vector3d}. @kwarg Vector_kwds: Optional, additional B{C{Vector}} keyword arguments, ignored if C{B{Vector}=None}.
@return: 2-Tuple with two trilaterated points, each a B{C{Vector}} instance. Both points are the same instance if all three spheres abut/intersect in a single point.
@raise ImportError: Package C{numpy} not found, not installed or older than version 1.15.
@raise IntersectionError: No intersection, colinear or concentric centers or trilateration failed some other way.
@raise TypeError: Invalid B{C{center1}}, B{C{center2}} or B{C{center3}}.
@raise UnitError: Invalid B{C{radius1}}, B{C{radius2}} or B{C{radius3}}.
@note: Package U{numpy<https://pypi.org/project/numpy>} is required, version 1.15 or later.
@see: Norrdine, A. U{I{An Algebraic Solution to the Multilateration Problem}<https://www.ResearchGate.net/publication/ 275027725_An_Algebraic_Solution_to_the_Multilateration_Problem>} and U{I{implementation}<https://www.ResearchGate.net/publication/ 288825016_Trilateration_Matlab_Code>}. ''' Radius_(radius1=radius1, low=eps), center2, radius2, center3, radius3, eps=eps, Vector=Vector, **Vector_kwds) raise IntersectionError(center1=center1, radius1=radius1, center2=center2, radius2=radius2, center3=center3, radius3=radius3, txt=str(x))
# (INTERNAL) Intersect three spheres or circles, see L{trilaterate3d2} # above, separated to allow callers to embellish any exceptions
# map numpy 4-vector to floats and split
# compute x, y and z and return as Vector
# non-complex roots of a polynomial
# check for concentric or too distant spheres else:
(c2, Radius_(radius2=r2, low=eps)), (c3, Radius_(radius3=r3, low=eps))):
else: # quadratic polynomial coefficients, ordered (^0, ^1, ^2) z.dot(x) * 2 - Z0, # fdot(Z, -_0_5, *x.xyz) * 2 z.length2) # fdot(Z, _0_0, *z.xyz)
finally: # restore numpy error handling
raise FloatingPointError(_txt(c1, r1, c2, r2) or _txt(c1, r1, c3, r3) or _txt(c2, r2, c3, r3) or (_colinear_ if _iscolinearWith(c1, c2, c3, eps=eps) else _no_intersection_)) t *= 2
t = v, v else: # "lowest" intersection first (to avoid test failures)
# return v3d if it's a L{Vector3d} instance
# return a named Vector instance else:
# **) MIT License # # Copyright (C) 2016-2020 -- mrJean1 at Gmail -- All Rights Reserved. # # Permission is hereby granted, free of charge, to any person obtaining a # copy of this software and associated documentation files (the "Software"), # to deal in the Software without restriction, including without limitation # the rights to use, copy, modify, merge, publish, distribute, sublicense, # and/or sell copies of the Software, and to permit persons to whom the # Software is furnished to do so, subject to the following conditions: # # The above copyright notice and this permission notice shall be included # in all copies or substantial portions of the Software. # # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS # OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL # THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR # OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, # ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR # OTHER DEALINGS IN THE SOFTWARE. |