OpenLB 1.8.1
Loading...
Searching...
No Matches
olb::Line3D< T > Struct Template Reference

Definition of a analytical line embedded in 3D space. More...

#include <line3D.h>

+ Collaboration diagram for olb::Line3D< T >:

Public Member Functions

 Line3D ()=default
 
Line3DoriginAt (const Vector< T, 3 > &origin)
 Center the line at the given origin vector.
 
Line3DcenteredIn (const Cuboid3D< T > &cuboid)
 Center the line relative to the given cuboid.
 
Line3DparallelTo (const Vector< T, 3 > &direction)
 Set the direction of the line parallel to a vector.
 
Line3DnormalTo (const Vector< T, 3 > &normal)
 Calculate the direction vector of the line to be orthogonal to the given normal.
 
bool isParallelToX () const
 
bool isParallelToY () const
 
bool isParallelToZ () const
 

Public Attributes

Vector< T, 3 > origin
 
Vector< T, 3 > u
 
Vector< T, 3 > normal
 

Detailed Description

template<typename T>
struct olb::Line3D< T >

Definition of a analytical line embedded in 3D space.

Line3D defines a line using its origin and a direction vector.

Definition at line 37 of file line3D.h.

Constructor & Destructor Documentation

◆ Line3D()

template<typename T >
olb::Line3D< T >::Line3D ( )
default

Member Function Documentation

◆ centeredIn()

template<typename T >
Line3D< T > & olb::Line3D< T >::centeredIn ( const Cuboid3D< T > & cuboid)

Center the line relative to the given cuboid.

Returns
Line3D reference for further construction

Definition at line 45 of file line3D.hh.

46{
47 const Vector<T,3>& cuboidOrigin = cuboid.getOrigin();
48 const Vector<int,3>& extend = cuboid.getExtent();
49 const T deltaR = cuboid.getDeltaR();
50
51 origin[0] = (cuboidOrigin[0] + 0.5 * deltaR * extend[0]);
52 origin[1] = (cuboidOrigin[1] + 0.5 * deltaR * extend[1]);
53 origin[2] = (cuboidOrigin[2] + 0.5 * deltaR * extend[2]);
54 origin[0] -= 2*std::numeric_limits<T>::epsilon()*util::fabs(origin[0]);
55 origin[1] -= 2*std::numeric_limits<T>::epsilon()*util::fabs(origin[1]);
56 origin[2] -= 2*std::numeric_limits<T>::epsilon()*util::fabs(origin[2]);
57
58 return *this;
59}
Expr fabs(Expr x)
Definition expr.cpp:230
Vector< T, 3 > origin
Definition line3D.h:38

References olb::util::fabs(), olb::Cuboid< T, D >::getDeltaR(), olb::Cuboid< T, D >::getExtent(), and olb::Cuboid< T, D >::getOrigin().

+ Here is the call graph for this function:

◆ isParallelToX()

template<typename T >
bool olb::Line3D< T >::isParallelToX ( ) const
Returns
true iff normal is orthogonal to X axis

Definition at line 103 of file line3D.hh.

104{
105 return util::nearZero(util::dotProduct3D(normal, {1,0,0}));
106}
T dotProduct3D(const Vector< T, 3 > &a, const Vector< T, 3 > &b)
dot product, only valid in 3d
bool nearZero(T a) any_platform
return true if a is close to zero
Definition util.h:402
Vector< T, 3 > normal
Definition line3D.h:40

References olb::util::dotProduct3D(), and olb::util::nearZero().

+ Here is the call graph for this function:

◆ isParallelToY()

template<typename T >
bool olb::Line3D< T >::isParallelToY ( ) const
Returns
true iff normal is orthogonal to Y axis

Definition at line 109 of file line3D.hh.

110{
111 return util::nearZero(util::dotProduct3D(normal, {0,1,0}));
112}

References olb::util::dotProduct3D(), and olb::util::nearZero().

+ Here is the call graph for this function:

◆ isParallelToZ()

template<typename T >
bool olb::Line3D< T >::isParallelToZ ( ) const

Definition at line 114 of file line3D.hh.

115{
116 return util::nearZero(util::dotProduct3D(normal, {0,0,1}));
117}

References olb::util::dotProduct3D(), and olb::util::nearZero().

+ Here is the call graph for this function:

◆ normalTo()

template<typename T >
Line3D< T > & olb::Line3D< T >::normalTo ( const Vector< T, 3 > & normal)

Calculate the direction vector of the line to be orthogonal to the given normal.

Returns
Line3D reference for further construction

Definition at line 75 of file line3D.hh.

76{
77 normal = normalize(n);
78 // Check if normal is aligned with any of the axes
80 // Normal is along the z-axis
81 u = {T(1), T(0), T(0)};
82 } else if (util::nearZero(normal[0]) && util::nearZero(normal[2])){
83 // Normal is along the y-axis
84 u = {T(1), T(0), T(0)};
85 } else if (util::nearZero(normal[1]) && util::nearZero(normal[2])) {
86 // Normal is along the x-axis
87 u = {T(0), T(1), T(0)};
88 } else {
89 // Use cross product with a vector not parallel to the normal to find u
90 Vector<T,3> arbitraryVec = (util::nearZero(normal[0]) && util::nearZero(normal[1]))
91 ? Vector<T,3>{T(1), T(0), T(0)}
92 : Vector<T,3>{T(0), T(1), T(0)};
93 u = crossProduct(normal, arbitraryVec);// Calculate orthogonal vector
94 }
95 u = normalize(u);
96 OstreamManager clout ("Test");
97 clout <<"Vector"<<u <<std::endl;
99 return *this;
100}
auto crossProduct(const ScalarVector< T, D, IMPL > &a, const ScalarVector< T, D, IMPL_ > &b) any_platform
Definition vector.h:274
constexpr Vector< T, D > normalize(const ScalarVector< T, D, IMPL > &a, T scale=T{1})
Definition vector.h:284
#define OLB_POSTCONDITION(COND)
Definition olbDebug.h:47
Vector< T, 3 > u
Definition line3D.h:39

References olb::crossProduct(), olb::util::dotProduct3D(), olb::util::nearZero(), olb::normalize(), and OLB_POSTCONDITION.

+ Here is the call graph for this function:

◆ originAt()

template<typename T >
Line3D< T > & olb::Line3D< T >::originAt ( const Vector< T, 3 > & origin)

Center the line at the given origin vector.

Returns
Line3D reference for further construction

Definition at line 35 of file line3D.hh.

36{
37 origin[0] = o[0] - 2*std::numeric_limits<T>::epsilon()*util::fabs(o[0]);
38 origin[1] = o[1] - 2*std::numeric_limits<T>::epsilon()*util::fabs(o[1]);
39 origin[2] = o[2] - 2*std::numeric_limits<T>::epsilon()*util::fabs(o[2]);
40
41 return *this;
42}

References olb::util::fabs().

+ Here is the call graph for this function:

◆ parallelTo()

template<typename T >
Line3D< T > & olb::Line3D< T >::parallelTo ( const Vector< T, 3 > & direction)

Set the direction of the line parallel to a vector.

Returns
Line3D reference for further construction

Definition at line 62 of file line3D.hh.

63{
64 u = direction;
65 // help vektor which is not parallel to u
66 Vector<T,3> helper = (u[0] == 0 && u[1] == 0) ? Vector<T,3>({1, 0, 0}) : Vector<T,3>({0, 0, 1});
67
68 normal = normalize(crossProduct(u, helper));
69
71 return *this;
72}
Vector(T &&t, Ts &&... ts) -> Vector< std::remove_cvref_t< T >, 1+sizeof...(Ts)>

References olb::crossProduct(), olb::util::dotProduct3D(), olb::util::nearZero(), olb::normalize(), and OLB_POSTCONDITION.

+ Here is the call graph for this function:

Member Data Documentation

◆ normal

template<typename T >
Vector<T,3> olb::Line3D< T >::normal

Definition at line 40 of file line3D.h.

◆ origin

template<typename T >
Vector<T,3> olb::Line3D< T >::origin

Definition at line 38 of file line3D.h.

◆ u

template<typename T >
Vector<T,3> olb::Line3D< T >::u

Definition at line 39 of file line3D.h.


The documentation for this struct was generated from the following files: