MayaFlux 1.0.0
Digital-First Multimedia Processing Framework
Loading...
Searching...
No Matches

◆ generate_regular_polygon()

MAYAFLUX_API std::vector< glm::vec3 > MayaFlux::Kinesis::generate_regular_polygon ( const glm::vec3 &  center,
float  radius,
size_t  sides,
const glm::vec3 &  normal = glm::vec3(0, 0, 1),
float  phase_offset = 0.0F 
)

Generate vertices of a regular n-gon.

Parameters
centerPolygon centroid
radiusCircumradius (center to vertex distance)
sidesNumber of sides (must be >= 3)
normalPolygon plane normal
phase_offsetAngular offset in radians (default: 0)
Returns
N+1 vertices (closed path)

Vertices positioned at angles: θ_k = (2πk/N) + phase_offset

Definition at line 174 of file GeometryPrimitives.cpp.

180{
181 if (sides < 3) {
182 sides = 3;
183 }
184
185 std::vector<glm::vec3> vertices;
186 vertices.reserve(sides + 1);
187
188 glm::vec3 n = glm::normalize(normal);
189 glm::vec3 u;
190
191 if (std::abs(n.z) < 0.9F) {
192 u = glm::normalize(glm::cross(n, glm::vec3(0, 0, 1)));
193 } else {
194 u = glm::normalize(glm::cross(n, glm::vec3(1, 0, 0)));
195 }
196
197 glm::vec3 v = glm::cross(n, u);
198
199 float angle_step = glm::two_pi<float>() / static_cast<float>(sides);
200
201 for (size_t i = 0; i <= sides; ++i) {
202 float angle = static_cast<float>(i) * angle_step + phase_offset;
203 float cos_a = std::cos(angle);
204 float sin_a = std::sin(angle);
205
206 glm::vec3 position = center + radius * (cos_a * u + sin_a * v);
207
208 vertices.push_back(position);
209 }
210
211 return vertices;
212}
std::optional< glm::vec3 > position
Definition Decoder.cpp:93
float radius

References position, and radius.