Loading...
Searching...
No Matches
triangle2D Class Reference

2-D triangle and queries More...

#include <triangle2D.H>

Inheritance diagram for triangle2D:
Collaboration diagram for triangle2D:

Public Member Functions

 triangle2D (const vector2D &a, const vector2D &b, const vector2D &c, const bool orient=false)
 Construct from 3 2-D points.
 triangle2D (const vector &a3d, const vector &b3d, const vector &c3d, const vector &axis1, const vector &axis2, const bool orient=false)
 Construct from 3 3-D points and axes.
label order () const
 Returns: 1 if points are ordered in anti-clockwise direction -1 if points are ordered in clockwise direction 0 if the triangle has collapsed to a line.
label snapClosePoints (const triangle2D &triB)
 Snap [this] triangle's points to those of triB if they are within absTol.
void interArea (const triangle2D &triB, vector2D &centre, scalar &area) const
 Return the intersection centre and area.
scalar interArea (const triangle2D &triB) const
 Return the intersection area.
bool overlaps (const triangle2D &triB) const
 Return true if triB overlaps.
scalar area () const noexcept
 Return the triangle area.
vector2D centre () const
 Return the triangle centre.
bool contains (const triangle2D &tri) const
 Return true if tri is within this triangle.
bool isSame (const triangle2D &triB) const
 Return true if triB is the same as this triangle.
bool pointInside (const vector2D &p) const
 Return true if t point p is inside this triangle.
Public Member Functions inherited from FixedList< vector2D, 3 >
 FixedList ()=default
 Default construct.
autoPtr< FixedList< vector2D, N > > clone () const
 Clone.
const vector2Dcdata () const noexcept
 Return pointer to the underlying array serving as data storage.
vector2Ddata () noexcept
 Return pointer to the underlying array serving as data storage.
const char * cdata_bytes () const noexcept
 Return pointer to the underlying array serving as data storage,.
char * data_bytes () noexcept
 Return pointer to the underlying array serving as data storage,.
vector2Dget () noexcept
 Element access using compile-time indexing.
vector2Dfront () noexcept
 Access first element of the list, position [0].
vector2Dback () noexcept
 Access last element of the list, position [N-1].
label fcIndex (const label i) const noexcept
 Return the forward circular index, i.e. next index which returns to the first at the end of the list.
const vector2DfcValue (const label i) const
 Return forward circular value (ie, next value in the list).
label rcIndex (const label i) const noexcept
 Return the reverse circular index, i.e. previous index which returns to the last at the beginning of the list.
const vector2DrcValue (const label i) const
 Return reverse circular value (ie, previous value in the list).
void checkStart (const label start) const
 Check start is within valid range [0,size).
void checkSize (const label size) const
 Check size is identical to template parameter N.
void checkIndex (const label i) const
 Check index is within valid range [0,N).
bool uniform () const
 True if all entries have identical values, and list is non-empty.
bool contains (const vector2D &val) const
 True if the value is contained in the list.
label find (const vector2D &val) const
 Find index of the first occurrence of the value.
label rfind (const vector2D &val, label pos=-1) const
 Find index of the last occurrence of the value.
void resize (const label n)
 Dummy function, to make FixedList consistent with List Any resizing is ignored (Fatal with bad sizing in full debug).
void resize_fill (const label n, const vector2D &val)
 Set val for all elements. Any resizing is ignored (Fatal with bad sizing in full debug).
void resize_nocopy (const label n)
 Dummy function, to make FixedList consistent with List Any resizing is ignored (Fatal with bad sizing in full debug).
void setSize (const label n)
 Dummy function, to make FixedList consistent with List.
void fill (const vector2D &val)
 Assign all entries to the given value.
void moveFirst (const label i)
 Move element to the first position.
void moveLast (const label i)
 Move element to the last position.
void swapFirst (const label i)
 Swap element with the first element.
void swapLast (const label i)
 Swap element with the last element.
void transfer (FixedList< vector2D, N > &list)
 Transfer by swapping using a move assignment for the content of the individual list elements.
vector2Doperator[] (const label i)
 Return element of FixedList.
void operator= (const UList< vector2D > &list)
 Assignment to UList operator. Takes linear time.
iterator begin () noexcept
 Return an iterator to begin traversing the FixedList.
iterator end () noexcept
 Return an iterator to end traversing the FixedList.
const_iterator cbegin () const noexcept
 Return const_iterator to begin traversing the constant FixedList.
const_iterator cend () const noexcept
 Return const_iterator to end traversing the constant FixedList.
reverse_iterator rbegin ()
 Return reverse_iterator to begin reverse traversing the FixedList.
reverse_iterator rend ()
 Return reverse_iterator to end reverse traversing the FixedList.
const_reverse_iterator crbegin () const
 Return const_reverse_iterator to begin reverse traversing FixedList.
const_reverse_iterator crend () const
 Return const_reverse_iterator to end reverse traversing FixedList.
void swap (FixedList< vector2D, N > &other)
 Swap lists by swapping the content of the individual list elements.
bool operator== (const FixedList< vector2D, N > &list) const
 Equality operation on FixedLists of the same type.
bool operator!= (const FixedList< vector2D, N > &list) const
 The opposite of the equality operation. Takes linear time.
bool operator< (const FixedList< vector2D, N > &list) const
 Compare two FixedLists lexicographically. Takes linear time.
bool operator> (const FixedList< vector2D, N > &list) const
 Compare two FixedLists lexicographically. Takes linear time.
bool operator<= (const FixedList< vector2D, N > &list) const
 Return true if !(a > b). Takes linear time.
bool operator>= (const FixedList< vector2D, N > &list) const
 Return true if !(a < b). Takes linear time.
IstreamreadList (Istream &is)
 Read from Istream, discarding contents of existing List.
OstreamwriteList (Ostream &os, const label shortLen=0) const
 Write List, with line-breaks in ASCII when length exceeds shortLen.
vector2Dfirst () noexcept
 Access first element of the list, position [0] - front().
vector2Dlast () noexcept
 Access last element of the list, position [N-1] - back().
bool found (const vector2D &val, label pos=0) const
 Same as contains().

Static Public Member Functions

static void writeOBJ (Ostream &os, const triangle2D &tri, label offset)
 Write the triangle in OBJ format.
static label nClosePoints (const triangle2D &triA, const triangle2D &triB)
 Return the number of similar points between two triangles.
static scalar area (const vector2D &a, const vector2D &b, const vector2D &c)
 Return the signed area.
static bool lineSegmentIntersectionPoint (const vector2D &lp1, const vector2D &lp2, const vector2D &sp1, const vector2D &sp2, vector2D &intersection)
 Set the intersection between a line and segment Return true if lines intersect.
static bool lineIntersectionPoint (const vector2D &a, const vector2D &b, const vector2D &c, const vector2D &d, vector2D &intersection)
 Set the intersection between two lines Return true if lines intersect.
static bool lineIntersects (const vector2D &a, const vector2D &b, const vector2D &c, const vector2D &d)
 Return true if lines ab and cd intersect.
Static Public Member Functions inherited from FixedList< vector2D, 3 >
static const FixedList< vector2D, N > & null () noexcept
 Return a null FixedList (reference to a nullObject). Read/write access is questionable.
static std::streamsize size_bytes () noexcept
 Number of contiguous bytes for the list data,.
static std::streamsize byteSize ()
 Number of contiguous bytes for the list data, runtime FatalError if type is not contiguous.
static constexpr bool empty () noexcept
 Always false since zero-sized FixedList is compile-time disabled.
static constexpr label size () noexcept
 Return the number of elements in the FixedList.
static constexpr unsigned max_size () noexcept
 The dimensioned size (template parameter N) of the FixedList.

Static Public Attributes

static int debug = 0
static scalar relTol = 1e-8
 Relative tolerance.
static scalar absTol = 1e-10
 Absolute tolerance.

Additional Inherited Members

Public Types inherited from FixedList< vector2D, 3 >
typedef vector2D value_type
 The value type the FixedList contains.
typedef vector2Dpointer
 The pointer type for non-const access to value_type items.
typedef const vector2Dconst_pointer
 The pointer type for const access to value_type items.
typedef vector2Dreference
 The type used for storing into value_type objects.
typedef const vector2Dconst_reference
 The type used for reading from constant value_type objects.
typedef vector2Diterator
 Random access iterator for traversing FixedList.
typedef const vector2Dconst_iterator
 Random access iterator for traversing FixedList.
typedef label size_type
 The type to represent the size of a FixedList.
typedef label difference_type
 The difference between iterator objects.
typedef std::reverse_iterator< iteratorreverse_iterator
 Reverse iterator (non-const access).
typedef std::reverse_iterator< const_iteratorconst_reverse_iterator
 Reverse iterator (const access).
Protected Member Functions inherited from FixedList< vector2D, 3 >
void writeEntry (Ostream &os) const
 Write the FixedList with its compound type.

Detailed Description

2-D triangle and queries

Source files

Definition at line 48 of file triangle2D.H.

Constructor & Destructor Documentation

◆ triangle2D() [1/2]

triangle2D ( const vector2D & a,
const vector2D & b,
const vector2D & c,
const bool orient = false )

Construct from 3 2-D points.

Definition at line 40 of file triangle2D.C.

References b, and FixedList< vector2D, 3 >::FixedList().

Referenced by centre(), contains(), interArea(), interArea(), isSame(), lineIntersects(), nClosePoints(), overlaps(), pointInside(), snapClosePoints(), triangle2D(), and writeOBJ().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ triangle2D() [2/2]

triangle2D ( const vector & a3d,
const vector & b3d,
const vector & c3d,
const vector & axis1,
const vector & axis2,
const bool orient = false )

Construct from 3 3-D points and axes.

Definition at line 64 of file triangle2D.C.

References triangle2D().

Here is the call graph for this function:

Member Function Documentation

◆ order()

Foam::label order ( ) const
inline

Returns: 1 if points are ordered in anti-clockwise direction -1 if points are ordered in clockwise direction 0 if the triangle has collapsed to a line.

Definition at line 192 of file triangle2DI.H.

References Foam::mag(), and Foam::sign().

Referenced by interArea(), and lineIntersects().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ writeOBJ()

void writeOBJ ( Ostream & os,
const triangle2D & tri,
label offset )
inlinestatic

Write the triangle in OBJ format.

Definition at line 25 of file triangle2DI.H.

References Foam::endl(), Foam::nl, os(), and triangle2D().

Referenced by interArea().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ nClosePoints()

Foam::label nClosePoints ( const triangle2D & triA,
const triangle2D & triB )
inlinestatic

Return the number of similar points between two triangles.

Definition at line 44 of file triangle2DI.H.

References FixedList< vector2D, 3 >::FixedList(), forAll, and triangle2D().

Referenced by overlaps().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ area() [1/2]

Foam::scalar area ( const vector2D & a,
const vector2D & b,
const vector2D & c )
inlinestatic

Return the signed area.

Definition at line 71 of file triangle2DI.H.

References b, and Vector2D< Cmpt >::perp().

Referenced by interArea(), and interArea().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ lineSegmentIntersectionPoint()

bool lineSegmentIntersectionPoint ( const vector2D & lp1,
const vector2D & lp2,
const vector2D & sp1,
const vector2D & sp2,
vector2D & intersection )
inlinestatic

Set the intersection between a line and segment Return true if lines intersect.

Definition at line 93 of file triangle2DI.H.

References debug, Foam::endl(), Foam::mag(), Foam::nl, os(), Vector2D< Cmpt >::perp(), relTol, s(), Vector2D< Cmpt >::x(), and Vector2D< Cmpt >::y().

Referenced by lineIntersectionPoint().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ lineIntersectionPoint()

bool lineIntersectionPoint ( const vector2D & a,
const vector2D & b,
const vector2D & c,
const vector2D & d,
vector2D & intersection )
inlinestatic

Set the intersection between two lines Return true if lines intersect.

Definition at line 149 of file triangle2DI.H.

References b, and lineSegmentIntersectionPoint().

Referenced by interArea().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ lineIntersects()

bool lineIntersects ( const vector2D & a,
const vector2D & b,
const vector2D & c,
const vector2D & d )
inlinestatic

Return true if lines ab and cd intersect.

Definition at line 162 of file triangle2DI.H.

References b, DebugInfo, Foam::endl(), order(), and triangle2D().

Referenced by overlaps().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ snapClosePoints()

Foam::label snapClosePoints ( const triangle2D & triB)

Snap [this] triangle's points to those of triB if they are within absTol.

Returns the number of snapped points

Definition at line 86 of file triangle2D.C.

References FixedList< vector2D, 3 >::FixedList(), forAll, and triangle2D().

Referenced by faceAreaWeightAMI2D::storeInterArea().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ interArea() [1/2]

void interArea ( const triangle2D & triB,
vector2D & centre,
scalar & area ) const

Return the intersection centre and area.

Definition at line 111 of file triangle2D.C.

References area(), centre(), debug, Foam::endl(), FixedList< vector2D, 3 >::FixedList(), Foam::Info, lineIntersectionPoint(), n, Foam::name(), Foam::nl, order(), os(), p0, triangle2D(), writeOBJ(), Foam::Zero, and VectorSpace< Form, Cmpt, Ncmpts >::zero.

Referenced by interArea().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ interArea() [2/2]

Foam::scalar interArea ( const triangle2D & triB) const

Return the intersection area.

Definition at line 258 of file triangle2D.C.

References area(), interArea(), triangle2D(), and Foam::Zero.

Here is the call graph for this function:

◆ overlaps()

bool overlaps ( const triangle2D & triB) const

Return true if triB overlaps.

Definition at line 269 of file triangle2D.C.

References contains(), Foam::j1(), lineIntersects(), nClosePoints(), and triangle2D().

Here is the call graph for this function:

◆ area() [2/2]

Foam::scalar area ( ) const
inlinenoexcept

Return the triangle area.

Definition at line 186 of file triangle2DI.H.

References Foam::noexcept.

◆ centre()

Foam::vector2D centre ( ) const
inline

Return the triangle centre.

Definition at line 85 of file triangle2DI.H.

References triangle2D().

Referenced by interArea().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ contains()

bool contains ( const triangle2D & tri) const
inline

Return true if tri is within this triangle.

Definition at line 198 of file triangle2DI.H.

References pointInside(), and triangle2D().

Referenced by overlaps().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ isSame()

bool isSame ( const triangle2D & triB) const
inline

Return true if triB is the same as this triangle.

Definition at line 207 of file triangle2DI.H.

References triangle2D().

Here is the call graph for this function:

◆ pointInside()

bool pointInside ( const vector2D & p) const
inline

Return true if t point p is inside this triangle.

Definition at line 218 of file triangle2DI.H.

References p, and triangle2D().

Referenced by contains().

Here is the call graph for this function:
Here is the caller graph for this function:

Member Data Documentation

◆ debug

int debug = 0
static

Definition at line 67 of file triangle2D.H.

Referenced by interArea(), and lineSegmentIntersectionPoint().

◆ relTol

Foam::scalar relTol = 1e-8
static

Relative tolerance.

Definition at line 72 of file triangle2D.H.

Referenced by lineSegmentIntersectionPoint(), and faceAreaWeightAMI2D::storeInterArea().

◆ absTol

Foam::scalar absTol = 1e-10
static

Absolute tolerance.

Definition at line 77 of file triangle2D.H.


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