Free Electron
RayPlaneIntersect.h
Go to the documentation of this file.
1 /* Copyright (C) 2003-2021 Free Electron Organization
2  Any use of this software requires a license. If a valid license
3  was not distributed with this file, visit freeelectron.org. */
4 
5 /** @file */
6 
7 #ifndef __solve_RayPlaneIntersect_h__
8 #define __solve_RayPlaneIntersect_h__
9 
10 namespace fe
11 {
12 namespace ext
13 {
14 
15 /**************************************************************************//**
16  @brief Find intersection between ray and plane
17 
18  @ingroup solve
19 *//***************************************************************************/
20 template <typename T>
22 {
23  public:
24 static T solve(const Vector<3,T>& center,const Vector<3,T>& facing,
25  const T radius,
26  const Vector<3,T>& origin,
27  const Vector<3,T>& direction);
28 
29 static void resolveContact(const Vector<3,T>& center,
30  const Vector<3,T>& facing,
31  const T radius,
32  const Vector<3,T>& origin,
33  const Vector<3,T>& direction,
34  const T range,
35  Vector<3,T>& intersection,
36  Vector<3,T>& normal);
37 };
38 
39 // direction must be normalized
40 template <typename T>
41 inline T RayPlaneIntersect<T>::solve(const Vector<3,T>& center,
42  const Vector<3,T>& facing,T radius,
43  const Vector<3,T>& origin, const Vector<3,T>& direction)
44 {
45  const T incident=dot(facing,direction);
46  if(incident==0.0f)
47  {
48  return T(-1);
49  }
50 // return (dot(facing,center)-dot(facing,origin))/incident;
51  return dot(facing,center-origin)/incident;
52 }
53 
54 // direction must be normalized
55 template <typename T>
57  const Vector<3,T>& center,
58  const Vector<3,T>& facing,
59  const T radius,
60  const Vector<3,T>& origin,
61  const Vector<3,T>& direction,
62  const T range,
63  Vector<3,T>& intersection,
64  Vector<3,T>& normal)
65 {
66  normal=facing;
67  intersection=origin+direction*range;
68 }
69 
70 } /* namespace ext */
71 } /* namespace fe */
72 
73 #endif /* __solve_RayPlaneIntersect_h__ */
74 
75 
Find intersection between ray and circular solid.
Definition: RayDiskIntersect.h:21
Find intersection between ray and plane.
Definition: RayPlaneIntersect.h:21
kernel
Definition: namespace.dox:3