RayZaler 0.1
The free opto-mechanical simulation framework
Circular.h
1//
2// Copyright (c) 2024 Gonzalo José Carracedo Carballal
3//
4// This program is free software: you can redistribute it and/or modify
5// it under the terms of the GNU Lesser General Public License as
6// published by the Free Software Foundation, either version 3 of the
7// License, or (at your option) any later version.
8//
9// This program is distributed in the hope that it will be useful, but
10// WITHOUT ANY WARRANTY; without even the implied warranty of
11// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12// GNU Lesser General Public License for more details.
13//
14// You should have received a copy of the GNU Lesser General Public
15// License along with this program. If not, see
16// <http://www.gnu.org/licenses/>
17//
18
19#ifndef _SURFACES_CIRCULAR_H
20#define _SURFACES_CIRCULAR_H
21
22#include <GLHelpers.h>
23#include <SurfaceShape.h>
24
25namespace RZ {
27 Real m_radius;
28 Real m_radius2;
29 Real m_a = 1;
30 Real m_b = 1;
31 Real m_a2 = 1;
32 Real m_b2 = 1;
33 bool m_obstruction = false;
34
35 std::vector<GLfloat> m_vertices;
36 std::vector<GLfloat> m_grid;
37 std::vector<std::vector<Real>> m_edges;
38
39 void recalculate();
40 void renderOpenGLAperture();
41 void renderOpenGLObstruction();
42
43 public:
44 CircularFlatSurface(Real radius);
45 virtual ~CircularFlatSurface() = default;
46
47 virtual std::vector<std::vector<Real>> const &edges() const override;
48 void setRadius(Real);
49 void setEccentricity(Real);
50
51 //
52 // Calculate radius and eccentricity from width and height. Given that:
53 //
54 // x^2 / A^2 + y^2 / B^2 = 1
55 //
56 // With A = aR and B = bR, then:
57 //
58 // width = 2A = 2aR
59 // height = 2B = 2bR
60 //
61 // Since we want to make sure that pi R^2 = piAB, then:
62 //
63 // pi width * height / 4 = pi R^2 => R = sqrt(width * height) / 2
64 //
65 static inline void
66 radiusEccentricity(Real &R, Real &e, Real width, Real height)
67 {
68 Real a2, b2;
69
70 R = .5 * sqrt(width * height);
71 a2 = .5 * width / R;
72 a2 *= a2;
73 b2 = .5 * height / R;
74 b2 *= b2;
75
76 if (b2 < a2)
77 e = +sqrt(1 - b2 * b2);
78 else
79 e = -sqrt(1 - a2 * a2);
80 }
81
82 inline Real
83 a() const
84 {
85 return sqrt(m_a2);
86 }
87
88 inline Real
89 b() const
90 {
91 return sqrt(m_b2);
92 }
93
94 inline Real
95 a2() const
96 {
97 return m_a2;
98 }
99
100 inline Real
101 b2() const
102 {
103 return m_b2;
104 }
105
106 void setObstruction(bool);
107
108 virtual bool intercept(
109 Vec3 &coord,
110 Vec3 &n,
111 Real &tIgnore,
112 Vec3 const &origin,
113 Vec3 const &direction) const override;
114
115 virtual Real area() const override;
116 virtual std::string name() const override;
117
118 virtual void generatePoints(
119 const ReferenceFrame *,
120 Real *pointArr,
121 Real *normals,
122 unsigned int N) override;
123
124 virtual void renderOpenGL() override;
125 };
126}
127
128#endif // _SURFACES_CIRCULAR_H
Definition: Circular.h:26
Definition: ReferenceFrame.h:59
Definition: SurfaceShape.h:31
Definition: Vector.h:66