52 lines
784 B
C
52 lines
784 B
C
|
#ifndef BLUECORE_PLANE_H
|
||
|
#define BLUECORE_PLANE_H
|
||
|
|
||
|
#include "Scalar.h"
|
||
|
#include "Vector.h"
|
||
|
|
||
|
namespace BlueCore
|
||
|
{
|
||
|
template <class T>
|
||
|
class PlaneTemplate
|
||
|
{
|
||
|
public:
|
||
|
Vector3Template<T> _n;
|
||
|
T _d;
|
||
|
|
||
|
/**
|
||
|
* contructor
|
||
|
*/
|
||
|
inline PlaneTemplate() : _d( 0. )
|
||
|
{
|
||
|
}
|
||
|
|
||
|
|
||
|
/**
|
||
|
* contructor
|
||
|
*/
|
||
|
inline PlaneTemplate(
|
||
|
Vector3Template<T> a,
|
||
|
Vector3Template<T> b,
|
||
|
Vector3Template<T> c )
|
||
|
{
|
||
|
_n = (a - b).cross(a - c).normalized();
|
||
|
_d = _n.dot( a );
|
||
|
}
|
||
|
|
||
|
|
||
|
/**
|
||
|
* distance
|
||
|
*/
|
||
|
inline T distance( const Vector3Template<T> a )
|
||
|
{
|
||
|
return _n.dot( a ) - _d;
|
||
|
}
|
||
|
};
|
||
|
|
||
|
typedef PlaneTemplate<float> PlaneFloat;
|
||
|
typedef PlaneTemplate<double> PlaneDouble;
|
||
|
typedef PlaneTemplate<Scalar> Plane;
|
||
|
}
|
||
|
|
||
|
#endif
|