Package: vectometry
vectometryThe Python packagevectometryimplements a Point object as well as a Vector object and the common vector operations in 3-dimensional space as well as for 2-dimensions. All functions can be used as the function itself, or viaMagical FunctionsandOperator Overloading. That means, for example the magnitude of a vector A can be calculated byvectometry.norm(A), but also by the Built-In functionabs(A). And for example the scalar product of vectors A and B can be calculated byvectometry.dot(A,B), but also by the (*)-operator:A*B.Developed by InformaticFreak (c) 2021Installationpip install vectometryDocumentationCreating Vector and PointA Point object or Vector object can be initialized by different ways.At first by three single real numbers.fromvectometryimport*p1=Point(1,2,-3)v1=Vector(1,2,-3)Or by a list or tuple of three real numbers.p2=Point([2,-4,6])p3=Point((3,3,3))v2=Vector([2,-4,6])v3=Vector((3,3,3))A Vector object can also be created by two Point objects, that means a Vector from Point p1 to Point p2.v4=Vector(p1,p2)v4=p2-p1v4#=> Vector(1, -6, 9)A point or vector for only 2-dimensions can also be created by the same Point object or Vector object, for this only two coordinates must be passed by a list/tuple or as singe	values. The remaining third coordinate will be set to zero.p2D=Point([5,6])p2D#=> Point(5, 6, 0)v2D=Vector(1,2)v2D#=> Vector(1, 2, 0)Compare position relationships of vectorsPerpendicular (orthogonal)Two vectors can be perpendicular (orthogonal) to each other, which means that the smaller angle between the two vector is 90 degrees.is_orthogonal(v1,v2)#=> FalseCollinear (parallel/anti-parallel)Two vectors are collinear, if they are parallel or anti-parallel to each other.is_collinear(v1,v2)#=> FalseComplanarThree vectors can be in the same plane, that means they are complanar.is_complanar(v1,v2,v3)#=> FalseCalculation of common vector operationsAll operations and calculations can be used by importing the functions. The basic operations are implemented withoperator overloading, so regular operators can be used for same result.AdditionBoth lines calculates the addition of two Vector objects. It returns the same Vector object in both orders.add(v1,v2)#=> Vector(3, -2, 3)v1+v2The addition of two Point objects returns a Vector object as the negated displacement of both Point objects.add(p1,p2)#=> Vector(3, -2, 3)p1+p2SubtractionSubtracts the one Vector object from the other Vector object. It return a Vector object.sub(v1,v2)#=> Vector(-1, 6, -9)v1-v2The difference of two Point objects returns a Vector object as the displacement of both Point objects.sub(p1,p2)#=> Vector(-1, 6, -9)p1-p2Multiplication by a real numberMultiplication of a Vector object by a real number returns a Vector object. The order of both factors doesn't matter.n=4mul(v1,n)#=> Vector(4, 8, -12)v1*nDivision by a real numberA Vector object devided by a real number means the multiplication of a Vector object by the reciprocal of the same number. It returns a Vector object only be calculated in this order.m=2div(v1,m)#=> Vector(0.5, 1.0, -1.5)v1/mv1*(1/m)Negative Vector or PointIt returns a Vector pointing in the negative direction, which means it is anti-parallel.neg(v1)#=> Vector(-1, -2, 3)-v1It return a Point object with negated coordinates.neg(p1)#=> Point(-1, -2, 3)-p1MagnitudeThe magnitude of a Vector object describes the length. It can be calculated from both lines and returns a positive real number including zero.norm(v1)#=> 3.7416573867739413abs(v1)Unit VectorIt returns the unit vector of a Vector object, it means a vector with the same direction but a magnitude of one.v1u=unit(v1)v1u#=> Vector(0.2672612419124244, 0.5345224838248488, -0.8017837257372732)norm(v1u)#=> 1.0Dot/Scalar ProductBoth lines calculates the dot product of two Vector objects. The dot product returns a real number.dot(v1,v2)#=> -24v1*v2Cross/Vector ProductBoth lines calculates the cross product of two Vector objects. The cross product returns a Vector object.cross(v1,v2)#=> Vector(0, -12, -8)v1%v2DeterminantCalculates the determinant of three Vector objects. It returns a real number.det(v1,v2,v3)#=> -60The same result is calculated by a combination of the cross product and dot product:dot(cross(v1,v2),v3)v1%v2*v3AngleThe lines calculates the smaller angle between two Vector objects, the result returns a real number. At third position the mode can be specified between degree with"deg"and radian with"rad". Degrees is optional and the default mode.angle(v1,v2)#=> 148.997280866126angle(v1,v2,"deg")angle(v1,v2,"rad")#=> 2.6004931276326473Area of a parallelogramThe following function calculates the area of a parallelogram spanned by two Vector objects. It returns a positive real number including zero.area(v1,v2)#=> 14.422205101855956Volume of a parallelepipedIt calculates the volume of a parallelepiped spanned by three Vector objects. It returns a positive real number including zero.spate(v1,v2,v3)#=> 60MiscellaneousGet and set coordinatesThe single coordinates of a Point object or Vector object can be set to the given value at first position of the specified x-, y- or z-method. No matter if the value is specified, the (new) coordinate is returned as a real number.An example:v=Vector(1,2,3)v.x()#=> 1v#=> Vector(1, 2, 3)v.x(5)#=> 5v#=> Vector(5, 2, 3)Get Point of a VectorIt returns the coordinates of the point on which the Vector object pointing as an independent Point object.v=Vector(1,2,3)v.point()#=> Point(1, 2, 3)Round a Point or VectorIt rounds the coordinates of a Point object or Vector object to the given decimal digits, default is zero decimal digits.v=Vector(0.3454,2.15,-7.14)round(v,1)#=> Vector(0.3, 2.1, -7.1)Iteration and lists/tuplesA Point object and a Vector object can be iterated, all three coordinates are swept.An example:p=Point(1,2,3)[cforcinp]#=> [1, 2, 3]Another way to get a list/tuple of the coordinates of a Point object or Vector object are the following functions:list(p)#=> [1, 2, 3]tuple(p)#=> (1, 2, 3)The amount of dimensions of a Point object or Vector object in 3-dimensional space are always3, but the length function works anyway.len(p)#=> 3len(v)#=> 3Copies/DuplicatesIt returns an independent copy of a Point object or Vector object.An example:v=Vector(1,2,3)v_indep=v.copy()v_indep.x(-4)v_dep=vv_dep.x(-8)v#=> Vector(-8, 2, 3)v_indep#=> Vector(-4, 2, 3)v_dep#=> Vector(-8, 2, 3)