Core 1.0
Plane Class Reference

A plane defined by its analytic equation. More...

#include <plane.h>

Inheritance diagram for Plane:
Slab

Public Member Functions

 Plane ()
 Empty.
 Plane (const Vector &, const double &)
 Creates a plane given normal and distance.
 Plane (const Vector &, const Vector &)
 Creates a plane given normal and vertex.
 Plane (const Vector &)
 Creates a plane given normal passing through the origin.
 ~Plane ()
 Empty.
bool Intersect (const Ray &, double &) const
 Compute the intersection between a plane and a ray.
bool Inside (const Vector &) const
 Check if a point is inside or outside the plane.
int Side (const Vector &) const
 Check if a point lies inside, outside or even on the plane.
Vector Normal () const
 Returns the normal to the plane.
Vector Vertex () const
 Finds a vertex on the plane.
double Coeff () const
 Returns the coefficient of the plane.
double R (const Vector &) const
 Compute the squared distance to the half space delimited by the plane.
double Signed (const Vector &) const
 Compute the signed distance between a point and the plane.
double Eval (const Vector &) const
 Evaluates the equation of the plane.
void Transform (const Matrix4 &)
 Transforms a plane given an affine homogeneous transformation matrix. The normal is transformed by the inverse transpose of the linear part of the matrix, which is valid for non uniform scaling and shearing.
void Translate (const double &)
 Translates a plane in the direction of its normal.
void Rotate (const Matrix &)
 Rotate a plane.
void Scale (const double &)
 Scale a plane.
Vector Symmetry (const Vector &) const
 Compute the point symmetric to the argument point.
Box Symmetric (const Box &) const
 Compute the bounding box of the symmetric argument box.
Segment Symmetric (const Segment &) const
 Compute the symmetric segment.
Sphere Symmetric (const Sphere &) const
 Compute the symmetric sphere.
Vector Reflect (const Vector &) const
 Compute the reflected direction.
bool Refract (const Vector &, const double &, Vector &) const
 Compute the refracted direction.
Vector Intersect (const Line &) const
 Compute the intersection between a plane and a line.
bool Intersect (const Segment &, double &) const
 Compute the intersection between a plane and a segment.
Quadric Equation (const Ray &) const
 Compute the quadric equation of the Euclidean distance to the plane.
Frame GetFrame () const
 Return a Frame attached to the plane.
Axis Intersect (const Plane &) const
 Compute the intersection between two planes.

Static Public Member Functions

static void Cast (const Vector &, double &, double &)
 Compute the inverse mapping coordinates of a point.
static Vector Intersection (const Plane &, const Plane &, const Plane &)
 Compute the intersection between three planes.
static QVector< Vector > ConvexPoints (const QVector< Plane > &)
 Compute the intersection of a set of half spaces.
static Vector Reflect (const Vector &, const Vector &)
 Given an input (normalized) normal, compute a reflected direction. The code is the same as:
static bool Refract (const Vector &, const Vector &, const double &, Vector &)
 Compute the refracted direction.

Static Public Attributes

static const double epsilon = 1e-06
 Small value for checking intersection with a ray.
static const Plane XY
 Reference z-axis horizontal plane.
static const Plane YZ
 Reference x-axis plane.
static const Plane ZX
 Reference y-axis plane.

Protected Attributes

Vector n = Vector::Z
 Plane normal.
double cqc = 0.0
 Plane coefficient.

Friends

std::ostream & operator<< (std::ostream &s, const Plane &plane)
 Overloaded.

Detailed Description

A plane defined by its analytic equation.

This class serves as a base core class for binary space patitionning or constructive solid geometry in ray-tracing.

Constructor & Destructor Documentation

◆ Plane() [1/3]

Plane::Plane ( const Vector & n,
const double & c )
inlineexplicit

Creates a plane given normal and distance.

The equation of the plane is: \(\ep \cdot \en - c = 0\).

Parameters
nNormal, should be unit.
cPlane constant.

◆ Plane() [2/3]

Plane::Plane ( const Vector & n,
const Vector & p )
explicit

Creates a plane given normal and vertex.

Parameters
nPlane normal, should be unit.
pAny point on the plane.

◆ Plane() [3/3]

Plane::Plane ( const Vector & n)
explicit

Creates a plane given normal passing through the origin.

Parameters
nPlane normal, should be unit.

Member Function Documentation

◆ Cast()

void Plane::Cast ( const Vector & p,
double & u,
double & v )
static

Compute the inverse mapping coordinates of a point.

Parameters
pPoint that will be projected on the plane.
u,vReturned coordinates.

◆ ConvexPoints()

QVector< Vector > Plane::ConvexPoints ( const QVector< Plane > & planes)
static

Compute the intersection of a set of half spaces.

This is a O(n^4) algorithm

A better version in O(n^3) could be implemented: see Finding the Intersection of Half-Spaces in Time O(n ln n). Preparata and Muller, Theoretical Computer Science 8, 45-55, 1979.

Returns a set of point representing the minimal convex polygon embedding all half spaces. The function doesn't check if the intersection is bounded or not.

Parameters
planesSet of planes.

◆ Equation()

Quadric Plane::Equation ( const Ray & ray) const

Compute the quadric equation of the Euclidean distance to the plane.

Parameters
rayThe ray.

◆ Eval()

double Plane::Eval ( const Vector & p) const
inline

Evaluates the equation of the plane.

This can be interpreted as a signed distance to the plane.

Parameters
pPoint.
See also
Plane::R(), Plane::Signed()

◆ GetFrame()

Frame Plane::GetFrame ( ) const

Return a Frame attached to the plane.

See also
Axis::GetFrame()

◆ Inside()

bool Plane::Inside ( const Vector & p) const

Check if a point is inside or outside the plane.

This function compares the sign strictly to 0.0, use Plane::Side() for a more fuzzy implementation.

Parameters
pPoint.
See also
Plane::Side().

◆ Intersect() [1/4]

Vector Plane::Intersect ( const Line & l) const

Compute the intersection between a plane and a line.

The line should not be parallel to the plane.

Parameters
lThe line.

◆ Intersect() [2/4]

Axis Plane::Intersect ( const Plane & plane) const

Compute the intersection between two planes.

The planes should not be parallel, otherwise the result is not defined. The normals of the planes do not need to be normalized.

The axis is directed by the cross product of the normal of this plane and the normal of the argument plane. Its origin is the point of the intersection line which is the closest to the origin.

Parameters
planeArgument plane.

◆ Intersect() [3/4]

bool Plane::Intersect ( const Ray & ray,
double & t ) const

Compute the intersection between a plane and a ray.

The intersection depth is returned if intersection occurs.

Parameters
rayThe ray.
tIntersection depth.

◆ Intersect() [4/4]

bool Plane::Intersect ( const Segment & s,
double & t ) const

Compute the intersection between a plane and a segment.

The intersection point can be computed using Segment::Vertex(const double&) if intersection occurs.

See also
Plane::Intersect(const Line&) const
Plane::Intersect(const Ray&) const
Parameters
sThe segment.
tPosition of the point if intersection occurs.

◆ Intersection()

Vector Plane::Intersection ( const Plane & a,
const Plane & b,
const Plane & c )
static

Compute the intersection between three planes.

Returns Vector::Null if two planes are complanar.

Parameters
a,b,cThree planes.

◆ R()

double Plane::R ( const Vector & p) const

Compute the squared distance to the half space delimited by the plane.

Parameters
pPoint.
See also
Plane::Eval()

◆ Reflect() [1/2]

Vector Plane::Reflect ( const Vector & d) const
inline

Compute the reflected direction.

Parameters
dDirection.

◆ Reflect() [2/2]

Vector Plane::Reflect ( const Vector & d,
const Vector & n )
inlinestatic

Given an input (normalized) normal, compute a reflected direction. The code is the same as:

Vector r=d-2.0*(n*d)*n;
Vector n
Plane normal.
Definition plane.h:20
Vectors in three dimensions.
Definition evector.h:13

◆ Refract() [1/2]

bool Plane::Refract ( const Vector & d,
const double & eta,
Vector & r ) const

Compute the refracted direction.

Parameters
dDirection.
etaIndex of incoming ray medium divided by the index of the other material.
rRefracted direction.

◆ Refract() [2/2]

bool Plane::Refract ( const Vector & d,
const Vector & n,
const double & eta,
Vector & r )
static

Compute the refracted direction.

Parameters
dDirection.
nNormal.
etaIndex of incoming ray medium divided by the index of the other material.
rRefracted direction.

◆ Rotate()

void Plane::Rotate ( const Matrix & r)

Rotate a plane.

Parameters
rRotation matrix.

\((R \en)\cdot(\ep-(R v))=(R \en)\cdot \ep-(R \en)\cdot(R v)=(R \en)\cdot \ep-\en\cdot v\) as an orthonormal matrix preserves the dot product ( \((Ra)\cdot (Rb)=(Ra)^t \cdot(Rb)\) and use the property of transpose and orthonormality of R).

◆ Scale()

void Plane::Scale ( const double & s)

Scale a plane.

Parameters
sScaling factor.

◆ Side()

int Plane::Side ( const Vector & p) const

Check if a point lies inside, outside or even on the plane.

The epsilon tolerance used for testing if the point is on the plane is \( 10^{-6} \).

Parameters
pPoint.

◆ Signed()

double Plane::Signed ( const Vector & p) const

Compute the signed distance between a point and the plane.

Parameters
pThe point.
See also
Plane::Eval(const Vector&) const

◆ Symmetric() [1/3]

Box Plane::Symmetric ( const Box & box) const

Compute the bounding box of the symmetric argument box.

Parameters
boxThe box.

◆ Symmetric() [2/3]

Segment Plane::Symmetric ( const Segment & segment) const

Compute the symmetric segment.

Parameters
segmentThe segment.

◆ Symmetric() [3/3]

Sphere Plane::Symmetric ( const Sphere & sphere) const

Compute the symmetric sphere.

Parameters
sphereThe sphere.

◆ Symmetry()

Vector Plane::Symmetry ( const Vector & p) const

Compute the point symmetric to the argument point.

The symmetric point is the mirror image of the point with respect to the plane, whose normal should be unit. A point of the plane is its own symmetric.

Parameters
pPoint.

◆ Transform()

void Plane::Transform ( const Matrix4 & M)

Transforms a plane given an affine homogeneous transformation matrix. The normal is transformed by the inverse transpose of the linear part of the matrix, which is valid for non uniform scaling and shearing.

Parameters
MMatrix.

◆ Translate()

void Plane::Translate ( const double & t)

Translates a plane in the direction of its normal.

Parameters
tTranslation distance.

◆ Vertex()

Vector Plane::Vertex ( ) const

Finds a vertex on the plane.

Compute the point on the plane which is nearest to the origin.

◆ operator<<

std::ostream & operator<< ( std::ostream & s,
const Plane & plane )
friend

Overloaded.

Parameters
sStream.
planeThe plane.