FastLED 3.9.15
Loading...
Searching...
No Matches

◆ compute()

vec2f fl::RosePath::compute ( float alpha)
overridevirtual

Implements fl::XYPathGenerator.

Definition at line 112 of file xypath_impls.cpp.hpp.

112 {
113 // Parametric equation for a rose curve (rhodonea)
114 // α in [0,1] → (x,y) on the rose curve
115
116 // Map alpha to the full range needed for the rose
117 // For a complete rose, we need to go through k*FL_PI radians where k is:
118 // - k = n if n is odd and d is 1
119 // - k = 2n if n is even and d is 1
120 // - k = n*d if n and d are coprime
121 // For simplicity, we'll use 2*FL_PI*n as a good approximation
122 float theta = alpha * 2.0f * FL_PI * params().n;
123
124 // Calculate the radius using the rose formula: r = cos(n*θ/d)
125 // We use cosine for a rose that starts with a petal at theta=0
126 float r = cosf(params().n * theta / params().d);
127
128 // Scale to ensure the rose fits within [-1, 1] range
129 // The absolute value ensures we get the proper shape
130 r = fabsf(r);
131
132 // Convert polar coordinates (r, theta) to Cartesian (x, y)
133 float x = r * cosf(theta);
134 float y = r * sinf(theta);
135
136 return vec2f(x, y);
137}
RosePathParams & params()
#define FL_PI
Definition math.h:26
vec2< float > vec2f
Definition geometry.h:333
float sinf(float value) FL_NOEXCEPT
Definition math.h:352
float fabsf(float value) FL_NOEXCEPT
Definition math.h:508
float cosf(float value) FL_NOEXCEPT
Definition math.h:358

References fl::cosf(), fl::fabsf(), FL_PI, fl::RosePathParams::n, params(), fl::sinf(), fl::x, and fl::y.

+ Here is the call graph for this function: