Carna Version 3.3.3
Loading...
Searching...
No Matches
RayPlaneHitTest.h
Go to the documentation of this file.
1/*
2 * Copyright (C) 2010 - 2015 Leonid Kostrykin
3 *
4 * Chair of Medical Engineering (mediTEC)
5 * RWTH Aachen University
6 * Pauwelsstr. 20
7 * 52074 Aachen
8 * Germany
9 *
10 */
11
12#ifndef RAYPLANEHITTEST_H_6014714286
13#define RAYPLANEHITTEST_H_6014714286
14
15#include <Carna/Carna.h>
16#include <Carna/base/math.h>
17#include <Carna/base/math/Ray.h>
19
24namespace Carna
25{
26
27namespace base
28{
29
30namespace math
31{
32
33
34
35// ----------------------------------------------------------------------------------
36// RayPlaneHitTest
37// ----------------------------------------------------------------------------------
38
48template< typename VectorType, typename ScalarType >
50{
51
52 bool myHitExists;
53 VectorType myHitLocation;
54
55public:
56
63
70
74 bool hitExists() const;
75
81 const VectorType& hitLocation() const;
82
83}; // RayPlaneHitTest
84
85
86template< typename VectorType, typename ScalarType >
91
92
93template< typename VectorType, typename ScalarType >
95{
96 return myHitExists;
97}
98
99
100template< typename VectorType, typename ScalarType >
102{
103 CARNA_ASSERT( hitExists() );
104 return myHitLocation;
105}
106
107
108template< typename VectorType, typename ScalarType >
110 ( const Ray< VectorType >& ray
111 , const VectorType& planeNormal
113{
114 CARNA_ASSERT( isEqual< ScalarType >( ray.direction.norm(), 1 ) );
116 CARNA_ASSERT( ray.direction.rows() == ray.origin.rows() && ray.origin.rows() == planeNormal.rows() );
117 CARNA_ASSERT( ray.direction.cols() == ray.origin.cols() && ray.origin.cols() == planeNormal.cols() && planeNormal.cols() == 1 );
118
119 if( isEqual< ScalarType >( ray.direction.dot( planeNormal ), 0 ) )
120 {
121 myHitExists = false;
122 }
123 else
124 {
125 const ScalarType rayLength = ( planeOriginOffset - ray.origin.dot( planeNormal ) ) / ray.direction.dot( planeNormal );
126 if( rayLength < 0 )
127 {
128 myHitExists = false;
129 }
130 else
131 {
132 myHitExists = true;
133 myHitLocation = ray.origin + ray.direction * rayLength;
134 CARNA_ASSERT( isEqual( planeNormal.dot( myHitLocation ), planeOriginOffset ) );
135 }
136 }
137}
138
139
140
141} // namespace Carna :: base :: math
142
143} // namespace Carna :: base
144
145} // namespace Carna
146
147#endif // RAYPLANEHITTEST_H_6014714286
Defines Carna::base::CarnaException, Carna::base::AssertionFailure.
#define CARNA_ASSERT(expression)
If the given expression is false, a break point is raised in debug mode and an AssertionFailure throw...
Defines Carna::base::math::Ray.
Represents an association.
Definition Association.h:45
Tests whether particular plane is hit by a Ray object.
bool hitExists() const
Tells whether a hit exists.
const VectorType & hitLocation() const
References the location of the hit.
void compute(const Ray< VectorType > &ray, const VectorType &planeNormal, ScalarType planeOriginOffset)
Performs a hit test of ray with the plane with planeNormal and planeOriginOffset. Use hitExists and h...
Defines Carna::base::math namespace and CARNA_FOR_VECTOR3UI.
bool isEqual(const InputType &x, const InputType &y)
Tells whether two objects are equal respectively to epsilon.
Definition math.h:174