Coverage for pygeodesy/vector3dBase.py : 95%

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 -*-
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>}. '''
_colinear_, _COMMASPACE_, _1_0 # from pygeodesy.utily import sincos2 # from .formy
'''(INTERNAL) Generic 3-D vector base class.
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 cartesian (= spherical n-vector) - great circle normal to vector - motion vector on earth's surface - etc. '''
'''New L{Vector3d} or C{Vector3dBase} instance.
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__
'''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 wrap: 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 set sign of s
a -= copysign0(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 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 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}. '''
else:
'''Get the length (norm, magnitude) of this vector (C{float}).
@see: Properties L{length2} and L{euclid}. '''
'''Get the length I{squared} of this vector (C{float}).
@see: Property L{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)
'''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)
'''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, ay * bx + sz, ay * by + c, ay * bz - sx), fdot(p, az * bx - sy, az * by + sx, az * bz + 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}}. '''
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 L{xyz}. ''' 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}). '''
'''Normalize this vector to unit length.
@kwarg ll: Optional, original location (C{LatLon}).
@return: Normalized vector (L{Vector3d}). ''' u._fromll = ll
'''(INTERNAL) Get 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}). '''
# **) MIT License # # Copyright (C) 2016-2021 -- 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. |