Skip to content

Commit

Permalink
Update for new coding standards. Fix header comment. Rename a couple …
Browse files Browse the repository at this point in the history
…of variables.
  • Loading branch information
anachrocomputer committed Jun 29, 2018
1 parent d5fc822 commit f339c92
Showing 1 changed file with 25 additions and 28 deletions.
53 changes: 25 additions & 28 deletions pappus.c
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
/* pappus --- draw the Pappus Chain on the plotter 2011-06-01 */
/* Copyright (c) 2011 John Honniball, Dorkbot Bristol */
/* Copyright (c) 2011 John Honniball, Froods Software Development */

#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <math.h>
#include "hpgllib.h"

double pappus_circle (double x0, double y0, double x, double y, double rad);
double pappus_circle(const double x0, const double y0, double x, double y, const double rad);

double Rad;
double Ycentre;

int main (int argc, char * const argv[])
int main(int argc, char * const argv[])
{
int opt;
double xc, yc;
Expand All @@ -20,53 +20,50 @@ int main (int argc, char * const argv[])
double r;
double r2;
double rad;
double csize;
double csize_mm;
int n;
int n2;

while ((opt = getopt (argc, argv, "no:p:s:t:v:")) != -1) {
while ((opt = getopt(argc, argv, "no:p:s:t:v:")) != -1) {
switch (opt) {
case 'n':
case 'o':
case 'p':
case 's':
case 't':
case 'v':
plotopt (opt, optarg);
plotopt(opt, optarg);
break;
default: /* '?' */
fprintf (stderr, "Usage: %s [-p pen] [-s <size>] [-t title]\n",
fprintf(stderr, "Usage: %s [-p pen] [-s <size>] [-t title]\n",
argv[0]);
fprintf (stderr, " <size> ::= A1 | A2 | A3 | A4 | A5\n");
// exit (EXIT_FAILURE);
fprintf(stderr, " <size> ::= A1 | A2 | A3 | A4 | A5\n");
// exit(EXIT_FAILURE);
}
}

plotbegin (0);
plotbegin(0);

getplotsize (&maxx, &maxy);
getplotsize(&maxx, &maxy);

xc = maxx / 2.0;
yc = maxy / 2.0;

Rad = yc;
Ycentre = yc;

/* Just draw with pen 1 for now. Maybe change pens half-way */
pencolr (0);
pencolr(0);

/* Draw outermost circle as large as will fit on a page */
circle (xc, yc, Rad);
circle(xc, yc, yc);

/* For an explanation of the mathematics of the Pappus
* Chain, see Wikipedia: http://en.wikipedia.org/wiki/Pappus_chain
*/

// r = 2.0 / 3.0;
r = 1.0 / 2.0;
n = 0;

/* pappus_circle ((1.0 - r) / 2.0, 0.0, (1.0 - r) / 2.0); */

do {
n2 = n * n;
r2 = (1.0 - r) * (1.0 - r);
Expand All @@ -75,12 +72,12 @@ int main (int argc, char * const argv[])
y = (n * r * (1.0 - r)) / ((n2 * r2) + r);
rad = ((1.0 - r) * r) / (2.0 * ((n2 * r2) + r));

// fprintf (stderr, "n = %d, x = %f, y = %f, rad = %f\n", n, x, y, rad);
// fprintf(stderr, "n = %d, x = %f, y = %f, rad = %f\n", n, x, y, rad);

csize = pappus_circle (xc, yc, x * maxy, y * maxy, rad * maxy);
csize_mm = pappus_circle(xc, yc, x * maxy, y * maxy, rad * maxy);

n++;
} while (csize > 1.5);
} while (csize_mm > 1.5);

/* Again, with the circles reflected. Repeating the entire sequence
* results in less wasted pen movement and hence faster plotting
Expand All @@ -96,25 +93,25 @@ int main (int argc, char * const argv[])
y = (n * r * (1.0 - r)) / ((n2 * r2) + r);
rad = ((1.0 - r) * r) / (2.0 * ((n2 * r2) + r));

// fprintf (stderr, "n = %d, x = %f, y = %f, rad = %f\n", n, x, y, rad);
// fprintf(stderr, "n = %d, x = %f, y = %f, rad = %f\n", n, x, y, rad);

csize = pappus_circle (xc, yc, (1.0 - x) * maxy, -y * maxy, rad * maxy);
csize_mm = pappus_circle(xc, yc, (1.0 - x) * maxy, -y * maxy, rad * maxy);

n++;
} while (csize > 1.5);
} while (csize_mm > 1.5);

plotend ();
plotend();

exit (0);
}


double pappus_circle (double x0, double y0, double x, double y, double rad)
double pappus_circle(const double x0, const double y0, double x, double y, const double rad)
{
x += x0 - Rad;
x += x0 - Ycentre;
y += y0;

circle (x, y, rad);
circle(x, y, rad);

return ((rad * 2.0) / 40.0);
}

0 comments on commit f339c92

Please sign in to comment.