FastLED 3.10.8
Loading...
Searching...
No Matches

◆ compute()

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

Implements fl::XYPathGenerator.

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

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

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

+ Here is the call graph for this function: