Skip to content

Commit

Permalink
Get the 'spiral()' function right. It wasn't doing the right number o…
Browse files Browse the repository at this point in the history
…f line segments to give a full 'turn'. TODO: move this function into the library, hopefully a correct version.
  • Loading branch information
anachrocomputer committed Aug 22, 2020
1 parent cd26db3 commit c571793
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 13 deletions.
11 changes: 5 additions & 6 deletions dala2.c
Original file line number Diff line number Diff line change
Expand Up @@ -977,16 +977,15 @@ void superellipse(const double x0, const double y0, const double a, const double

void spiral(const double cx, const double cy, const double radius, const double ang, const int n)
{
double theta = ang;
double thinc = 2.0 * M_PI / 72.0;
double delta = 2.0 * M_PI / 72.0;
int i;
int ptnumber = 72 * n;
int npts = 72 * n;

moveto(cx, cy);

for (i = 0; i < ptnumber; i++) {
theta += thinc;
const double r = (radius * i) / (double)ptnumber;
for (i = 1; i <= npts; i++) {
const double theta = ang + (delta * (double)i);
const double r = (radius * i) / (double)npts;
const double x = (r * cos(theta)) + cx;
const double y = (r * sin(theta)) + cy;

Expand Down
11 changes: 5 additions & 6 deletions dala2c.c
Original file line number Diff line number Diff line change
Expand Up @@ -126,18 +126,17 @@ int main (int argc, char * const argv[])

void spiral (double cx, double cy, double radius, double ang, int n)
{
double theta = ang;
double thinc = 2.0 * M_PI / 72.0;
double delta = 2.0 * M_PI / 72.0;
double r;
int i;
int ptnumber = 72 * n;
int npts = 72 * n;
double x, y;

moveto (cx, cy);

for (i = 0; i < ptnumber; i++) {
theta += thinc;
r = (radius * i) / (double)ptnumber;
for (i = 1; i <= npts; i++) {
const double theta = ang + (delta * (double)i);
r = (radius * i) / (double)npts;
x = (r * cos (theta)) + cx;
y = (r * sin (theta)) + cy;

Expand Down
2 changes: 1 addition & 1 deletion twist.c
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ void spiral(const double xc, const double yc, const double r1, const double r2,
int i;
const double dr = (r2 - r1) / (72.0 * n);

for (i = 0; i < (72 * n); i++) {
for (i = 0; i <= (72 * n); i++) {
const double theta = ang + (delta * i);
const double r = r1 + (dr * i);
const double x = (r * cos(theta)) + xc;
Expand Down

0 comments on commit c571793

Please sign in to comment.