mat_vec_fns_II.h File Reference
#include <cmath>
#include "mat_vec_types.h"

Go to the source code of this file.

Functions

template<class t_scalar >
bool sameSign (t_scalar a, t_scalar b)
 check whether two scalars have the same sign More...
 
int getMissingNode (int n0, int n1, int n2)
 
void getRestOfNodes (int iN, int &iO0, int &iO1, int &iO2)
 
void getMissingPair (int in0, int in1, int &on0, int &on1)
 
template<class t_scalar , class brr3 >
void arr3arr3Add (arr3_view< t_scalar, brr3 > vecA, arr3_view< t_scalar, brr3 > vecB, arr3_view< t_scalar, brr3 > res)
 
template<class t_scalar , class brr3 >
void arr3arr3Substract (arr3_view< t_scalar, brr3 > vecA, arr3_view< t_scalar, brr3 > vecB, arr3_view< t_scalar, brr3 > res)
 
template<class t_scalar , class brr3 >
void arr3arr3VectorProduct (arr3_view< t_scalar, brr3 > u, arr3_view< t_scalar, brr3 > v, arr3_view< t_scalar, brr3 > w)
 
template<class t_scalar , class brr3 >
t_scalar arr3arr3DotProduct (arr3_view< t_scalar, brr3 > vecA, arr3_view< t_scalar, brr3 > vecB)
 
template<class t_scalar , class brr3 >
void arr3Normalise (arr3_view< t_scalar, brr3 > e)
 
template<class t_scalar , class brr3 >
void arr3Normalise2 (arr3_view< t_scalar, brr3 > e, arr3_view< t_scalar, brr3 > n)
 
template<class t_scalar , class brr3 >
void arr3Resize (t_scalar f, arr3_view< t_scalar, brr3 > u)
 
template<class t_scalar , class brr3 >
void arr3Resize2 (t_scalar f, arr3_view< t_scalar, brr3 > u, arr3_view< t_scalar, brr3 > v)
 
template<class t_scalar , class brr3 >
void arr3Resize3 (t_scalar f, arr3_view< t_scalar, brr3 > u, arr3_view< t_scalar, brr3 > v)
 
template<class t_scalar , class brr3 >
void arr3Store (arr3_view< t_scalar, brr3 > u, arr3_view< t_scalar, brr3 > v)
 
template<class t_scalar , class brr3 >
t_scalar arr3arr3Distance (arr3_view< t_scalar, brr3 > vecA, arr3_view< t_scalar, brr3 > vecB)
 
template<class t_scalar , class brr3 >
t_scalar mag (arr3_view< t_scalar, brr3 > v)
 
template<class t_scalar , class brr3 >
t_scalar mag2 (arr3_view< t_scalar, brr3 > v)
 
template<class brr3 >
void arr3Initialise (brr3 &v)
 
template<class t_scalar , class brr3 >
t_scalar detByRows (arr3_view< t_scalar, brr3 > a, arr3_view< t_scalar, brr3 > b, arr3_view< t_scalar, brr3 > c)
 
template<class t_scalar , class brr3 >
t_scalar detByCols (arr3_view< t_scalar, brr3 > a, arr3_view< t_scalar, brr3 > b, arr3_view< t_scalar, brr3 > c)
 
template<class t_scalar , class brr3 >
void tangent (brr3 &vecA, brr3 &vecB, brr3 &t)
 
template<class t_scalar , class brr3 >
void getUnitNormal (brr3 &u, brr3 &v, brr3 &w)
 
template<class t_scalar , class brr3 >
void getNormal (brr3 &v1, brr3 &v2, brr3 &v3, brr3 &n)
 
template<class t_scalar , class brr3 >
void getNormalInwards (brr3(&tetA)[4], int n0, int n1, int n2, brr3(&n))
 
template<class t_scalar , class brr3 >
void getNormalInwards (brr3 &f0, brr3 &f1, brr3 &f2, brr3 &p3, brr3(&n))
 
template<class t_scalar , class brr3 >
bool sameSidePlane (brr3 &vec, brr3 &test, brr3 &p1, brr3 &p2, brr3 &p3)
 
template<class t_scalar , class brr3 >
bool sameSideLine (brr3 &e, brr3 &p1, brr3 &p2, brr3 &p3)
 
template<class t_scalar , class brr3 >
bool nodeInTet (brr3 &vec, brr3(tet)[4])
 
template<class t_scalar , class brr3 >
bool nodeInTet (brr3 &vec, brr3 &tet0, brr3 &tet1, brr3 &tet2, brr3 &tet3)
 
template<class t_scalar , class brr3 >
void linePlaneIntersectionPoint (brr3 &ip, brr3 &e1, brr3 &e2, brr3 &p1, brr3 &p2, brr3 &p3)
 
template<class t_scalar , class brr3 >
bool safeLinePlaneIntersectionPoint (brr3 &ip, brr3 &e1, brr3 &e2, brr3 &p1, brr3 &p2, brr3 &p3)
 
template<class t_scalar , class brr3 >
bool lineFaceIntersectionPoint (brr3(&ip), brr3(&e1), brr3(&e2), brr3(&p1), brr3(&p2), brr3(&p3))
 
template<class t_scalar , class brr3 >
bool isPointInFace (brr3 &ip, brr3 &p1, brr3 &p2, brr3 &p3)
 
template<class t_scalar , class brr3 >
bool intersectionPoint (brr3 &(ip), brr3(&e1), brr3(&e2), brr3(&tet)[4], int f1, int f2, int f3)
 
template<class t_scalar , class brr3 >
bool intersectionPoint (brr3 &ip, brr3 &e1, brr3 &e2, brr3 &f1, brr3 &f2, brr3 &f3)
 
template<class brr3 >
void faceCentroid (brr3 &p1, brr3 &p2, brr3 &p3, brr3 &c)
 
template<class t_scalar , class brr3 >
bool samePlane (brr3 &p1, brr3 &p2, brr3 &p3, brr3 &p4)
 
template<class t_scalar , class brr3 >
void intersectingPointToLine (arr3_view< t_scalar, brr3 > p0, arr3_view< t_scalar, brr3 > p1, arr3_view< t_scalar, brr3 > p2p1, arr3_view< t_scalar, brr3 > p3)
 
template<class t_scalar , class brr3 >
void intersectingPointToLine (vector3 &p0, arr3_view< t_scalar, brr3 > p1, arr3_view< t_scalar, brr3 > p2p1, arr3_view< t_scalar, brr3 > p3)
 
template<class t_scalar , class brr3 >
t_scalar distanceFromPointToLine (arr3_view< t_scalar, brr3 > p0, arr3_view< t_scalar, brr3 > p1, arr3_view< t_scalar, brr3 > p2)
 
template<class t_scalar , class brr3 >
t_scalar getTetrahedraVolume (arr3_view< t_scalar, brr3 > p0, arr3_view< t_scalar, brr3 > p1, arr3_view< t_scalar, brr3 > p2, arr3_view< t_scalar, brr3 > p3)
 
template<class brr3 >
void getTetrahedraCM (brr3 &p1, brr3 &p2, brr3 &p3, brr3 &p4, brr3 &c)
 
template<class t_scalar , class brr3 , class brr4 >
void getLocalCoordinatesForLinTet (arr3_view< t_scalar, brr3 > t0, arr3_view< t_scalar, brr3 > t1, arr3_view< t_scalar, brr3 > t2, arr3_view< t_scalar, brr3 > t3, arr3_view< t_scalar, brr3 > p, brr4 &phi)
 
template<class brr3 >
void vec3Vec3SubsToArr3 (vector3 &u, vector3 &v, brr3(&w))
 
void vec3Arr3SubsToArr3 (vector3 &u, arr3 &v, arr3 &w)
 
void arr3Vec3SubsToArr3 (arr3(&u), vector3 &v, arr3(&w))
 
void vec3Arr3AddToArr3 (vector3 &u, arr3(&v), arr3(&w))
 
void vec3Vec3AddToArr3 (vector3 &u, vector3 &v, arr3(&w))
 
void vec3ResizeToArr3 (scalar f, vector3 &u, arr3 &v)
 
scalar vec3Arr3DotProduct (vector3 &u, arr3 &v)
 

Function Documentation

◆ arr3arr3Add()

template<class t_scalar , class brr3 >
void arr3arr3Add ( arr3_view< t_scalar, brr3 >  vecA,
arr3_view< t_scalar, brr3 >  vecB,
arr3_view< t_scalar, brr3 >  res 
)

Add vectors vecA and vecB into res. res can also be vecA or vecB

SECTION 1 /////////////////////// Basic operations for arr3, i. e., scalar v[3]// Add vectors vecA and vecB into res. res can also be vecA or vecB

◆ arr3arr3Distance()

template<class t_scalar , class brr3 >
t_scalar arr3arr3Distance ( arr3_view< t_scalar, brr3 >  vecA,
arr3_view< t_scalar, brr3 >  vecB 
)

return the distance from vecA to vecB

◆ arr3arr3DotProduct()

template<class t_scalar , class brr3 >
t_scalar arr3arr3DotProduct ( arr3_view< t_scalar, brr3 >  vecA,
arr3_view< t_scalar, brr3 >  vecB 
)

return the dot product for arrays vecA and vecB

◆ arr3arr3Substract()

template<class t_scalar , class brr3 >
void arr3arr3Substract ( arr3_view< t_scalar, brr3 >  vecA,
arr3_view< t_scalar, brr3 >  vecB,
arr3_view< t_scalar, brr3 >  res 
)

res = vecA - vecB res can be either vecA or vecB

◆ arr3arr3VectorProduct()

template<class t_scalar , class brr3 >
void arr3arr3VectorProduct ( arr3_view< t_scalar, brr3 >  u,
arr3_view< t_scalar, brr3 >  v,
arr3_view< t_scalar, brr3 >  w 
)

w = u x v w must be different from u and v

w = u x v (w != u) && (w != v)

◆ arr3Initialise()

template<class brr3 >
void arr3Initialise ( brr3 &  v)

Initialise the input vector with (0, 0, 0)

Referenced by findCM(), maxVolume(), and maxVolumeAndArea().

◆ arr3Normalise()

template<class t_scalar , class brr3 >
void arr3Normalise ( arr3_view< t_scalar, brr3 >  e)

Normalise vector arr3 e

◆ arr3Normalise2()

template<class t_scalar , class brr3 >
void arr3Normalise2 ( arr3_view< t_scalar, brr3 >  e,
arr3_view< t_scalar, brr3 >  n 
)

Get the normalised vector of arr3 e into arr3 n

get the normalised vector of arr3 e into arr3 n

◆ arr3Resize()

template<class t_scalar , class brr3 >
void arr3Resize ( t_scalar  f,
arr3_view< t_scalar, brr3 >  u 
)

Given a scalar f, resize vector u

resize vector u, given scalar f

◆ arr3Resize2()

template<class t_scalar , class brr3 >
void arr3Resize2 ( t_scalar  f,
arr3_view< t_scalar, brr3 >  u,
arr3_view< t_scalar, brr3 >  v 
)

Given a scalar f, resize vector u into vector v

resize vector u into vector v, given scalar f

◆ arr3Resize3()

template<class t_scalar , class brr3 >
void arr3Resize3 ( t_scalar  f,
arr3_view< t_scalar, brr3 >  u,
arr3_view< t_scalar, brr3 >  v 
)

Given a scalar f, change v so that v += f*u

◆ arr3Store()

template<class t_scalar , class brr3 >
void arr3Store ( arr3_view< t_scalar, brr3 >  u,
arr3_view< t_scalar, brr3 >  v 
)

cp arr3 u into arr3 v

Referenced by intersectingPointToLine().

◆ arr3Vec3SubsToArr3()

void arr3Vec3SubsToArr3 ( arr3 u,
vector3 v,
arr3 w 
)

◆ detByCols()

template<class t_scalar , class brr3 >
t_scalar detByCols ( arr3_view< t_scalar, brr3 >  a,
arr3_view< t_scalar, brr3 >  b,
arr3_view< t_scalar, brr3 >  c 
)

calculate the determinant of a 3x3 matrix given by cols a, b, c

◆ detByRows()

template<class t_scalar , class brr3 >
t_scalar detByRows ( arr3_view< t_scalar, brr3 >  a,
arr3_view< t_scalar, brr3 >  b,
arr3_view< t_scalar, brr3 >  c 
)

calculate the determinant of a 3x3 matrix given by rows a, b, c

◆ distanceFromPointToLine()

template<class t_scalar , class brr3 >
t_scalar distanceFromPointToLine ( arr3_view< t_scalar, brr3 >  p0,
arr3_view< t_scalar, brr3 >  p1,
arr3_view< t_scalar, brr3 >  p2 
)

Given a line defined by points p1 and p2, return the distance from p0, to this line.

◆ faceCentroid()

template<class brr3 >
void faceCentroid ( brr3 &  p1,
brr3 &  p2,
brr3 &  p3,
brr3 &  c 
)

Return the center of coordinates for three points p1, p2, p3 in c

◆ getLocalCoordinatesForLinTet()

template<class t_scalar , class brr3 , class brr4 >
void getLocalCoordinatesForLinTet ( arr3_view< t_scalar, brr3 >  t0,
arr3_view< t_scalar, brr3 >  t1,
arr3_view< t_scalar, brr3 >  t2,
arr3_view< t_scalar, brr3 >  t3,
arr3_view< t_scalar, brr3 >  p,
brr4 &  phi 
)

◆ getMissingNode()

int getMissingNode ( int  n0,
int  n1,
int  n2 
)

Given 3 integers n0, n1, n2 return the index missing in the list [0,1,2,3]

Referenced by getBAndN(), getMissingPair(), getNormalInwards(), volumeAndAreaForIntPoint(), and volumeForIntPoint().

◆ getMissingPair()

void getMissingPair ( int  in0,
int  in1,
int &  on0,
int &  on1 
)

Given 1 integers iN, return the index missing indices of the list [0,1,2,3]

◆ getNormal()

template<class t_scalar , class brr3 >
void getNormal ( brr3 &  v1,
brr3 &  v2,
brr3 &  v3,
brr3 &  n 
)

calculate the unit normal vector n to the plane defined by the three points

calculate the normal vector n to the plane defined by the three points

◆ getNormalInwards() [1/2]

template<class t_scalar , class brr3 >
void getNormalInwards ( brr3(&)  tetA[4],
int  n0,
int  n1,
int  n2,
brr3 &  n 
)

Given the face formed by tetA[0]:tetA[1]:tetA[2] [ or the face formed by f0, f1, and f2, and knowing the remaining p3 for a tetrahedron ] get n, the normal to a face pointing inwards.

◆ getNormalInwards() [2/2]

template<class t_scalar , class brr3 >
void getNormalInwards ( brr3 &  f0,
brr3 &  f1,
brr3 &  f2,
brr3 &  p3,
brr3 &  n 
)

Given the face formed by f0, f1, and f2, and knowing the remaining p3 for a tetrahedron, get n, the normal to a face pointing inwards.

◆ getRestOfNodes()

void getRestOfNodes ( int  iN,
int &  iO0,
int &  iO1,
int &  iO2 
)

Given 1 integers iN, return the index missing indices of the list [0,1,2,3]

◆ getTetrahedraCM()

template<class brr3 >
void getTetrahedraCM ( brr3 &  p1,
brr3 &  p2,
brr3 &  p3,
brr3 &  p4,
brr3 &  c 
)

Return the center of coordinates for four points p1, p2, p3, p4 in c

◆ getTetrahedraVolume()

template<class t_scalar , class brr3 >
t_scalar getTetrahedraVolume ( arr3_view< t_scalar, brr3 >  p0,
arr3_view< t_scalar, brr3 >  p1,
arr3_view< t_scalar, brr3 >  p2,
arr3_view< t_scalar, brr3 >  p3 
)

◆ getUnitNormal()

template<class t_scalar , class brr3 >
void getUnitNormal ( brr3 &  u,
brr3 &  v,
brr3 &  w 
)

w = unit(u x v) (w != u) && (w != v)

◆ intersectingPointToLine() [1/2]

template<class t_scalar , class brr3 >
void intersectingPointToLine ( arr3_view< t_scalar, brr3 >  p0,
arr3_view< t_scalar, brr3 >  p1,
arr3_view< t_scalar, brr3 >  p2p1,
arr3_view< t_scalar, brr3 >  p3 
)

Given a line defined by point p1 and vector p2p1, get the intersecting point p3, in that line from a third point p0. Essentially implementing "Intersection of two lines in three-space", by Ronald Goldman, in Graphics Gems I.

◆ intersectingPointToLine() [2/2]

template<class t_scalar , class brr3 >
void intersectingPointToLine ( vector3 p0,
arr3_view< t_scalar, brr3 >  p1,
arr3_view< t_scalar, brr3 >  p2p1,
arr3_view< t_scalar, brr3 >  p3 
)

◆ intersectionPoint() [1/2]

template<class t_scalar , class brr3 >
bool intersectionPoint ( brr3 &  ip,
brr3 &  e1,
brr3 &  e2,
brr3(&)  tet[4],
int  f1,
int  f2,
int  f3 
)

Check whether an edge and a plane intersect, and return the intersection point ip and true if found, false otherwise. More specifically check that both:

  • both ends of the edge (e1 and e2) are on different sides of the plane defined by the vectors (tet[f2] - tet[f1]) and (tet[f3] - tet[f1]).
  • the intersection of a line is a point in the plane

Check whether an edge and a plane intersect, and return the intersection point ip and true if found, false otherwise. more specifically check that both:

  • both ends of the edge (e1 and e2) are on different sides of the plane defined by the vectors (tet[f2] - tet[f1]) and (tet[f3] - tet[f1]).
  • the intersection of a line is a point in the plane

◆ intersectionPoint() [2/2]

template<class t_scalar , class brr3 >
bool intersectionPoint ( brr3 &  ip,
brr3 &  e1,
brr3 &  e2,
brr3 &  f1,
brr3 &  f2,
brr3 &  f3 
)

Check whether an edge and a plane intersect, and return the intersection point ip and true if found, false otherwise. more specifically check that both:

  • both ends of the edge (e1 and e2) are on different sides of the plane defined by the vectors (f2 - f1) and (f3 - f1).
  • the intersection of a line is a point in the plane

◆ isPointInFace()

template<class t_scalar , class brr3 >
bool isPointInFace ( brr3 &  ip,
brr3 &  p1,
brr3 &  p2,
brr3 &  p3 
)

Check whether point ip is inside of the three half-planes formed by the triangle's edges p1, p2, p3.

◆ lineFaceIntersectionPoint()

template<class t_scalar , class brr3 >
bool lineFaceIntersectionPoint ( brr3 &  ip,
brr3 &  e1,
brr3 &  e2,
brr3 &  p1,
brr3 &  p2,
brr3 &  p3 
)

Return true and the intersection point ip of the line that passes through the points e1 and e2 and face defined by points p1, p2, p3 if this intersection actually occurs, and false otherwise.

Warning
p1, p2, and p3 are assumed to be non-colinear.

◆ linePlaneIntersectionPoint()

template<class t_scalar , class brr3 >
void linePlaneIntersectionPoint ( brr3 &  ip,
brr3 &  e1,
brr3 &  e2,
brr3 &  p1,
brr3 &  p2,
brr3 &  p3 
)

Find the intersection point of the line that passes through the points e1 and e2, and the plane defined by points p1, p2 and p3.

Warning
This function should be called ONLY in the case that intersection is known to occur.

find the intersection point of the line that passes through the points e1 and e2, and the plane defined by points p1, p2 and p3.

Warning
{this function should be called ONLY in the case that intersection is known to occur.}

◆ mag()

template<class t_scalar , class brr3 >
t_scalar mag ( arr3_view< t_scalar, brr3 >  v)

Return the length of a vector v

◆ mag2()

template<class t_scalar , class brr3 >
t_scalar mag2 ( arr3_view< t_scalar, brr3 >  v)

Return the squared length of a vector v

◆ nodeInTet() [1/2]

template<class t_scalar , class brr3 >
bool nodeInTet ( brr3 &  vec,
brr3(tet)  [4] 
)

check whether vector vec is in tetrahedron B. more specifically, it will be there if for each plane of the tetrahedron, the point is on the same side as the remaining vertex

◆ nodeInTet() [2/2]

template<class t_scalar , class brr3 >
bool nodeInTet ( brr3 &  vec,
brr3 &  tet0,
brr3 &  tet1,
brr3 &  tet2,
brr3 &  tet3 
)

◆ safeLinePlaneIntersectionPoint()

template<class t_scalar , class brr3 >
bool safeLinePlaneIntersectionPoint ( brr3 &  ip,
brr3 &  e1,
brr3 &  e2,
brr3 &  p1,
brr3 &  p2,
brr3 &  p3 
)

Return true and the intersection point of the line that passes through the points e1 and e2 and the plane defined by points p1, p2, p3 if this intersection actually occurs, and false otherwise.

Warning
p1, p2, and p3 are assumed to be non-colinear.

◆ samePlane()

template<class t_scalar , class brr3 >
bool samePlane ( brr3 &  p1,
brr3 &  p2,
brr3 &  p3,
brr3 &  p4 
)

Chech whether 4 points are on the same plane

◆ sameSideLine()

template<class t_scalar , class brr3 >
bool sameSideLine ( brr3 &  e,
brr3 &  p1,
brr3 &  p2,
brr3 &  p3 
)

Given 4 co-planar points, check if ip and p1 lay on the same side of the of the line formed by p2 and p3. More specifically we check whether pl23 x pl21 and pl23 x pl2e are parallel or antiparallel.

◆ sameSidePlane()

template<class t_scalar , class brr3 >
bool sameSidePlane ( brr3 &  vec,
brr3 &  test,
brr3 &  p1,
brr3 &  p2,
brr3 &  p3 
)

check if points vec and test are at the same side of the plane formed by p1, p2 and p3

◆ sameSign()

template<class t_scalar >
bool sameSign ( t_scalar  a,
t_scalar  b 
)

check whether two scalars have the same sign

check whether two scalars have the same sign

Referenced by getBAndN(), getNormalInwards(), and sameSidePlane().

◆ tangent()

template<class t_scalar , class brr3 >
void tangent ( brr3 &  vecA,
brr3 &  vecB,
brr3 &  t 
)

t = unit(vecA - vecB) t can be either vecA or vecB

◆ vec3Arr3AddToArr3()

void vec3Arr3AddToArr3 ( vector3 u,
arr3 v,
arr3 w 
)

◆ vec3Arr3DotProduct()

scalar vec3Arr3DotProduct ( vector3 u,
arr3 v 
)

◆ vec3Arr3SubsToArr3()

void vec3Arr3SubsToArr3 ( vector3 u,
arr3 v,
arr3 w 
)

◆ vec3ResizeToArr3()

void vec3ResizeToArr3 ( scalar  f,
vector3 u,
arr3 v 
)

Given a scalar f, resize vec3 u into arr3 u

◆ vec3Vec3AddToArr3()

void vec3Vec3AddToArr3 ( vector3 u,
vector3 v,
arr3 w 
)

◆ vec3Vec3SubsToArr3()

template<class brr3 >
void vec3Vec3SubsToArr3 ( vector3 u,
vector3 v,
brr3 &  w 
)

SECTION 3 //////////////////// Transition functions from vector3 to arr3 //