LibCarna Version 3.4.0
Loading...
Searching...
No Matches
RayPlaneHitTest.hpp
Go to the documentation of this file.
1/*
2 * Copyright (C) 2010 - 2016 Leonid Kostrykin
3 *
4 * Chair of Medical Engineering (mediTEC)
5 * RWTH Aachen University
6 * Pauwelsstr. 20
7 * 52074 Aachen
8 * Germany
9 *
10 *
11 * Copyright (C) 2021 - 2025 Leonid Kostrykin
12 *
13 */
14
15#ifndef RAYPLANEHITTEST_H_6014714286
16#define RAYPLANEHITTEST_H_6014714286
17
18#include <LibCarna/LibCarna.hpp>
22
28namespace LibCarna
29{
30
31namespace base
32{
33
34namespace math
35{
36
37
38
39// ----------------------------------------------------------------------------------
40// RayPlaneHitTest
41// ----------------------------------------------------------------------------------
42
51template< typename VectorType, typename ScalarType >
53{
54
55 bool myHitExists;
56 VectorType myHitLocation;
57
58public:
59
66
73
77 bool hitExists() const;
78
84 const VectorType& hitLocation() const;
85
86}; // RayPlaneHitTest
87
88
89template< typename VectorType, typename ScalarType >
94
95
96template< typename VectorType, typename ScalarType >
98{
99 return myHitExists;
100}
101
102
103template< typename VectorType, typename ScalarType >
105{
106 LIBCARNA_ASSERT( hitExists() );
107 return myHitLocation;
108}
109
110
111template< typename VectorType, typename ScalarType >
113 ( const Ray< VectorType >& ray
114 , const VectorType& planeNormal
116{
117 LIBCARNA_ASSERT( isEqual< ScalarType >( ray.direction.norm(), 1 ) );
119 LIBCARNA_ASSERT( ray.direction.rows() == ray.origin.rows() && ray.origin.rows() == planeNormal.rows() );
120 LIBCARNA_ASSERT( ray.direction.cols() == ray.origin.cols() && ray.origin.cols() == planeNormal.cols() && planeNormal.cols() == 1 );
121
122 if( isEqual< ScalarType >( ray.direction.dot( planeNormal ), 0 ) )
123 {
124 myHitExists = false;
125 }
126 else
127 {
128 const ScalarType rayLength = ( planeOriginOffset - ray.origin.dot( planeNormal ) ) / ray.direction.dot( planeNormal );
129 if( rayLength < 0 )
130 {
131 myHitExists = false;
132 }
133 else
134 {
135 myHitExists = true;
136 myHitLocation = ray.origin + ray.direction * rayLength;
137 LIBCARNA_ASSERT( isEqual( planeNormal.dot( myHitLocation ), planeOriginOffset ) );
138 }
139 }
140}
141
142
143
144} // namespace LibCarna :: base :: math
145
146} // namespace LibCarna :: base
147
148} // namespace LibCarna
149
150#endif // RAYPLANEHITTEST_H_6014714286
Defines LibCarna::base::LibCarnaException and LibCarna::base::AssertionFailure.
#define LIBCARNA_ASSERT(expression)
If the given expression is false, a break point is raised in debug mode and an AssertionFailure throw...
Contains forward-declarations.
Defines LibCarna::base::math::Ray.
Represents an association.
Tests whether particular plane is hit by a Ray object.
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...
bool hitExists() const
Tells whether a hit exists.
const VectorType & hitLocation() const
References the location of the hit.
Defines LibCarna::base::math namespace and LIBCARNA_FOR_VECTOR3UI.
bool isEqual(const InputType &x, const InputType &y)
Tells whether two objects are equal respectively to epsilon.
Definition math.hpp:178