From c571793267fdbbc7c6229071a3146c18c2c1b489 Mon Sep 17 00:00:00 2001 From: John Honniball Date: Sat, 22 Aug 2020 17:25:35 +0100 Subject: [PATCH] Get the 'spiral()' function right. It wasn't doing the right number of line segments to give a full 'turn'. TODO: move this function into the library, hopefully a correct version. --- dala2.c | 11 +++++------ dala2c.c | 11 +++++------ twist.c | 2 +- 3 files changed, 11 insertions(+), 13 deletions(-) diff --git a/dala2.c b/dala2.c index 80bfd3d..965f7a7 100644 --- a/dala2.c +++ b/dala2.c @@ -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; diff --git a/dala2c.c b/dala2c.c index 1853066..d59e8c8 100644 --- a/dala2c.c +++ b/dala2c.c @@ -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; diff --git a/twist.c b/twist.c index 9508ef4..5cfd156 100644 --- a/twist.c +++ b/twist.c @@ -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;