MeshLib
 
Loading...
Searching...
No Matches
MRPlane3.h
Go to the documentation of this file.
1#pragma once
2
3#include "MRVector3.h"
4
5namespace MR
6{
7
10template <typename T>
11struct Plane3
12{
14 T d = 0;
15
16 constexpr Plane3() noexcept = default;
17 constexpr Plane3( const Vector3<T> & n, T d ) noexcept : n( n ), d( d ) { }
18 template <typename U>
19 constexpr explicit Plane3( const Plane3<U> & p ) noexcept : n( p.n ), d( T( p.d ) ) { }
20 [[nodiscard]] constexpr static Plane3 fromDirAndPt( const Vector3<T> & n, const Vector3<T> & p ) { return { n, dot( n, p ) }; }
21
23 [[nodiscard]] T distance( const Vector3<T> & x ) const { return dot( n, x ) - d; }
24
26 [[nodiscard]] Plane3 operator -() const { return Plane3( -n, -d ); }
28 [[nodiscard]] const Plane3 & operator +() const { return *this; }
30 [[nodiscard]] Plane3 normalized() const
31 {
32 const auto len = n.length();
33 if ( len <= 0 )
34 return {};
35 const auto rlen = 1 / len;
36 return Plane3{ rlen * n, rlen * d };
37 }
38
40 [[nodiscard]] Vector3<T> project( const Vector3<T> & p ) const { return p - distance( p ) / n.lengthSq() * n; }
41};
42
45
49template <typename T>
50[[nodiscard]] inline Plane3<T> invTransformed( const Plane3<T> & pl, const AffineXf3<T> & ixf )
51{
52 return Plane3<T>{ ixf.A.transposed() * pl.n, pl.d - dot( pl.n, ixf.b ) };
53}
54
58template <typename T>
59[[nodiscard]] inline Plane3<T> transformed( const Plane3<T> & plane, const AffineXf3<T> & xf )
60{
61 return invTransformed( plane, xf.inverse() );
62}
63
64template <typename T>
65[[nodiscard]] inline bool operator == ( const Plane3<T> & a, const Plane3<T> & b )
66{
67 return a.n == b.n && a.d == b.d;
68}
69
70template <typename T>
71[[nodiscard]] inline bool operator != ( const Plane3<T> & a, const Plane3<T> & b )
72{
73 return !( a == b );
74}
75
77
78} // namespace MR
MRMESH_API bool operator==(const BitSet &a, const BitSet &b)
compare that two bit sets have the same set bits (they can be equal even if sizes are distinct but la...
bool operator!=(const SetBitIteratorT< T > &a, const SetBitIteratorT< T > &b)
Definition MRMesh/MRBitSet.h:259
Definition MRCameraOrientationPlugin.h:7
Definition MRMesh/MRAffineXf.h:14
V b
Definition MRMesh/MRAffineXf.h:19
M A
Definition MRMesh/MRAffineXf.h:18
Definition MRPlane3.h:12
constexpr Plane3() noexcept=default
Plane3 normalized() const
returns same plane represented with unit n-vector
Definition MRPlane3.h:30
Plane3< T > transformed(const Plane3< T > &plane, const AffineXf3< T > &xf)
Definition MRPlane3.h:59
Vector3< T > project(const Vector3< T > &p) const
finds the closest point on plane
Definition MRPlane3.h:40
T distance(const Vector3< T > &x) const
returns distance from given point to this plane (if n is a unit vector)
Definition MRPlane3.h:23
const Plane3 & operator+() const
returns same representation
Definition MRPlane3.h:28
Vector3< T > n
Definition MRPlane3.h:13
constexpr Plane3(const Plane3< U > &p) noexcept
Definition MRPlane3.h:19
T d
Definition MRPlane3.h:14
Plane3< T > invTransformed(const Plane3< T > &pl, const AffineXf3< T > &ixf)
Definition MRPlane3.h:50
Plane3 operator-() const
returns same plane represented with flipped direction of n-vector
Definition MRPlane3.h:26
static constexpr Plane3 fromDirAndPt(const Vector3< T > &n, const Vector3< T > &p)
Definition MRPlane3.h:20
Definition MRMesh/MRVector3.h:19