spirograph Namespace Reference

## Functions

template<std::size_t N>
void | spirograph (std::array< std::pair< double, double >, N > *points, double l, double k, double rot)
void | test ()
| Test function to save resulting points to a CSV file.

## Detailed Description

Functions related to spirograph.cpp

## Function Documentation

## spirograph()

template<std::size_t N>

void spirograph::spirograph | ( | std::array< std::pair< double, double >, N > * | points,
|  | double | l,
|  | double | k,
|  | double | rot
| ) |  |

Generate spirograph curve into arrays `x` and `y` such that the i^th point in 2D is represented by `(x[i],y[i])`. The generating function is given by:

\begin{eqnarray*} x &=& R\left[ (1-k) \cos (t) + l\cdot k\cdot\cos \left(\frac{1-k}{k}t\right) \right]\\ y &=& R\left[ (1-k) \sin (t) - l\cdot k\cdot\sin \left(\frac{1-k}{k}t\right) \right] \end{eqnarray*}

where

- \(R\) is the scaling parameter that we will consider \(=1\)
- \(l=\frac{\rho}{r}\) is the relative distance of marker from the centre of inner circle and \(0\le l\le1\)
- \(\rho\) is physical distance of marker from centre of inner circle
- \(r\) is the radius of inner circle
- \(k=\frac{r}{R}\) is the ratio of radius of inner circle to outer circle and \(0<k<1\)
- \(R\) is the radius of outer circle
- \(t\) is the angle of rotation of the point i.e., represents the time parameter

Since we are considering ratios, the actual values of \(r\) and \(R\) are immaterial.

Template Parameters

  N | number of points = size of array

Parameters

  [out] | points | Array of 2D points represented as std::pair
  | l | the relative distance of marker from the centre of inner circle and \(0\le l\le1\)
  | k | the ratio of radius of inner circle to outer circle and \(0<k<1\)
  | rot | the number of rotations to perform (can be fractional value)

{
double dt = rot * 2.f * M_PI / N;
double R = 1.f;
const double k1 = 1.f - k;
int32_t step = 0;
#ifdef _OPENMP
#pragma omp for
#endif
for (step = 0; step < N; step++) {
double t = dt * step;
double first = R * (k1 * std::cos(t) + l * k * std::cos(k1 * t / k));
double second = R * (k1 * std::sin(t) - l * k * std::sin(k1 * t / k));
points[0][step].first = first;
points[0][step].second = second;
}
}
std::cos
T cos(T... args)
std::sin
T sin(T... args)
Here is the call graph for this function: