geoclide.vecope module#
- geoclide.vecope.coordinate_system(v1, method='m2')#
Create orthogonal coordinate system(s) from a vector/set of vectors
- Parameters:
- v1Vector
The base vector(s) used to create the orthogonal coordinate system(s)
- method: str, optional
Default is ‘m2’ (method from pbrt v4), other choice is ‘m1’ (pbrt v2 and v3)
- Returns:
- v2Vector
The second vector(s) of the orthogonal coordinate system(s)
- v3Vector
The third vector(s) of the orthogonal coordinate system(s)
Examples
>>> import geoclide as gc >>> v1 = gc.Vector(0., 0., 1.) >>> v2, v3 = gc.coordinate_system(v1) (Vector(1.0, -0.0, -0.0), Vector(-0.0, 1.0, -0.0))
- geoclide.vecope.cross(a, b)#
The cross product
Warning
The cross product of 2 normals is not allowed
Definition of the cross product:
\((a × b) = ((a.y*b.z)-(a.z*b.y))x̂ + ((a.z*b.x)-(a.x*b.z))ŷ + ((a.x*b.y)-(a.y*b.x))\)
\((a × b) = ||a||*||b||*sin(θ)\)
where x̂, ŷ and ẑ are the unitary vectors respectively in axes x, y and z
- Parameters:
- aVector | Normal
The first vector(s) or normal(s) used for the cross product
- bVector | Normal
The second vector(s) or normal(s) used for the cross product
- Returns:
- outVector
The result(s) of the cross product
Examples
>>> import geoclide as gc >>> a = gc.Vector(0.,0.,1.) >>> b = gc.Vector(1.,0.,0.) >>> gc.cross(a,b) Vector(0.0, 1.0, 0.0)
- geoclide.vecope.distance(p1, p2)#
Compute the distance(s) between 2 points/set of points
- Parameters:
- p1Point
The first point(s)
- p2Point
The second point(s)
- Returns:
- outfloat | 1-D ndarray
The distance(s) between the 2 points/set of points
Examples
>>> p1 = gc.Point(0., 0., 0.) >>> p2 = gc.Point(0., 0., 10.) >>> gc.distance(p1,p2) 10.0 >>> p1 = gc.Point(1., 2., 1.9) >>> p2 = gc.Point(5., 15., 3.) >>> gc.distance(p1,p2) 13.64587849865299
- geoclide.vecope.dot(a, b)#
The dot/scalar product
Definition of the dot product:
\((a . b) = a.x*b.x + a.y*b.y + a.z*b.z\)
\((a . b) = ||a|| * ||b|| * cos(θ)\)
- Parameters:
- aVector | Normal
The first vector(s) or normal(s) used for the dot product
- bVector | Normal
The second vector(s) or normal(s) used for the dot product
- Returns:
- outfloat | 1-D ndarray
The result(s) of the dot product i.e. sum of products
Examples
>>> import geoclide as gc >>> a = gc.Vector(0., 0., 1.) >>> b = gc.Vector(math.sqrt(2.)/2., 0., math.sqrt(2.)/2.) >>> gc.dot(a,b) 0.7071067811865476
- geoclide.vecope.face_forward(a, b)#
Flip the vector(s)/normal(s) a if the vector(s)/normal(s) b is/are in the opposite direction(s)
It can be useful to flip a surface normal so that it lies in the same hemisphere as a given vector.
- Parameters:
- aVector | Normal
The vector(s) or normal(s) to potentially flip
- bVector | Normal
The base vector(s) or normal(s) used for the flip
- Returns:
- outVector | Normal
The potentially flipped vector(s) or normal(s)
Examples
>>> import geoclide as gc >>> n1 = gc.Normal(1., 0., 0.) >>> v1 = gc.Vector(-1., 0., 0.) >>> gc.face_forward(v1, n1) Vector(1.0, -0.0, -0.0)
- geoclide.vecope.normalize(v)#
Normalize a vector/normal or a set of vectors/normals
- Parameters:
- vVector | Normal
The vector(s) or normal(s) to be normalized
- Returns:
- outVector | Normal
The normalized vector(s)/normal(s)
Examples
>>> import geoclide as gc >>> v = gc.Vector(1.,0.,1.) >>> gc.normalize(v) Vector(0.7071067811865475, 0.0, 0.7071067811865475)
- geoclide.vecope.permute(a, ix=None, iy=None, iz=None)#
Permutes the vector(s)/point(s)/normal(s) x, y, z values according to the given indices
- Parameters:
- aVector | Point | Normal
The vector(s), point(s) or normal(s) used for permutation
- ixint | np.ndarray | list, optional
The index/indices of the value(s) we want to keep as a remplacement for the x component(s)
- iyint | np.ndarray | list, optional
The index/indices of the value(s) we want to keep as a remplacement for the y component(s)
- izint | np.ndarray | list, optional
The index/indices of the value(s) we want to keep as a remplacement for the z component(s)
- Returns:
- outVector | Point | Normal
The vector(s)/point(s)/normal(s) after the permute operation
Examples
>>> import geoclide as gc >>> v1 = gc.Vector(2., 3., 1.) >>> gc.permute(v1, 1, 0, 2) Vector(3.0, 2.0, 1.0) >>> gc.permute(v1, 1, 0, 2]) Vector(3.0, 2.0, 1.0) >>> p_set = np.array([[0.,0.,3.], [1.,0.,0.], [-0.5,0.,0.], [0.,-3.,0.]]) >>> p_set = gc.Point(p_set) >>> gc.permute(p_set, [2,0,0,1], 1, 2).to_numpy() array([[ 3. , 0. , 3. ], [ 1. , 0. , 0. ], [-0.5, 0. , 0. ], [ 0. , -3. , 0. ]])
- geoclide.vecope.vabs(a)#
Calculate the absolute value(s) of each component of the vector(s)/point(s)/normal(s)
- Parameters:
- aVector | Point | Normal
The vector(s)/point(s)/normal(s) used
- Returns:
- out: Vector | Point | Normal | 1-D ndarray
The vector(s)/point(s)/normal(s) with absolute values
- geoclide.vecope.vargmax(a)#
Get the index/indices of the vector(s)/point(s)/normal(s) components with the largest value(s)
- Parameters:
- aVector | Point | Normal
The vector(s)/point(s)/normal(s) used
- Returns:
- out: int | 1-D ndarray
The index/indices of the largest vector(s)/point(s)/normal(s) value(s)
Examples
>>> import geoclide as gc >>> v1 = gc.Vector(2.,3.,1.) >>> gc.argmax(v1) 1
- geoclide.vecope.vargmin(a)#
Get the index/indices of the vector(s)/point(s)/normal(s) components with the smallest value(s)
- Parameters:
- aVector | Point | Normal
The vector(s)/point(s)/normal(s) used
- Returns:
- out: int | 1-D ndarray
The index/indices of the smallest vector(s)/point(s)/normal(s) value(s)
Examples
>>> import geoclide as gc >>> v1 = gc.Vector(2.,3.,1.) >>> gc.argmin(v1) 2
- geoclide.vecope.vmax(a)#
Get the largest components value(s) of the vector(s)/point(s)/normal(s)
- Parameters:
- aVector | Point | Normal
The vector(s)/point(s)/normal(s) used
- Returns:
- out: float | 1-D ndarray
The largest vector(s)/point(s)/normal(s) value(s)
Examples
>>> import geoclide as gc >>> v1 = gc.Vector(2.,3.,1.) >>> gc.max(v1) 3
- geoclide.vecope.vmin(a)#
Get the smallest components value(s) of the vector(s)/point(s)/normal(s)
- Parameters:
- aVector | Point | Normal
The vector(s)/point(s)/normal(s) used
- Returns:
- out: float | 1-D ndarray
The smallest vector(s)/point(s)/normal(s) value(s)
Examples
>>> import geoclide as gc >>> v1 = gc.Vector(2.,3.,1.) >>> gc.min(v1) 1