Skip to content

Commit

Permalink
Fill upper right sub-plot and modify lower right. Add half-ellipse fu…
Browse files Browse the repository at this point in the history
…nction.
  • Loading branch information
anachrocomputer committed Sep 11, 2020
1 parent 32fc691 commit 6c4e59d
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 6 deletions.
2 changes: 1 addition & 1 deletion TODO.md
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ E.g. op, pconic, hconic.
* Convert Tarim's C++ 'spiro' to C and make it use the library too.
* Finish off some of the incomplete plots. E.g. hexagon, fraserspiral,
flake, qrplot, spiralsq, twist, zigzag.
* Fill the empty sub-plots in 'circle4', 'ellipse' and 'piscis'.
* Fill the empty sub-plots in 'circle4' and 'piscis'.
* Clean up the various 'dala' drawings. Eliminate the 'dala2c' variant
by adding colour to 'dala2.c'.
* Add run-time variation to 'dala2.c'.
Expand Down
53 changes: 48 additions & 5 deletions ellipse.c
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ void plot_ll(const double xc, const double yc, const double r1, const double r2)
void plot_lr(const double xc, const double yc, const double r1, const double r2);
void plot_ul(const double xc, const double yc, const double r1, const double r2);
void plot_ur(const double xc, const double yc, const double r1, const double r2);
void half_ellipse(const double x0, const double y0, const double a, const double b, const double theta);


int main(int argc, char * const argv[])
Expand Down Expand Up @@ -84,18 +85,24 @@ void plot_ll(const double xc, const double yc, const double r1, const double r2)
void plot_lr(const double xc, const double yc, const double r1, const double r2)
{
/* Inspired by "Japanese Optical and Geometrical Art" by
Hajime Ouchi, ISBN 0-486-23553-X, page 23, bottom */
Hajime Ouchi, ISBN 0-486-23553-X, page 85, lower right */
int i;
const double delta = (2.0 * M_PI) / 8.0;
const int n = 8;
const double delta = (2.0 * M_PI) / (double)n;
const double radius = r2 / 2.0;
const double r3 = radius * sqrt(2.0);

for (i = 0; i < 8; i++) {
for (i = 0; i < n; i++) {
const double theta = delta * (double)i;

const double x = xc + (radius * cos(theta));
const double y = yc + (radius * sin(theta));
const double x1 = xc + (r3 * cos(theta + delta));
const double y1 = yc + (r3 * sin(theta + delta));

ellipse(x, y, r1 / 2.0, r2 / 2.0, theta);
half_ellipse(x, y, r2 / 2.0, r1 / 2.0, theta - (M_PI / 2.0));
moveto(x1, y1);
lineto(xc, yc);
}
}

Expand All @@ -116,7 +123,21 @@ void plot_ul(const double xc, const double yc, const double r1, const double r2)

void plot_ur(const double xc, const double yc, const double r1, const double r2)
{
circle(xc, yc, r2);
int i;
const int n = 11;
const double delta = (2.0 * M_PI) / (double)n;
const double radius = r2 / 2.0;

// circle(xc, yc, r2);

for (i = 0; i < n; i++) {
const double theta = delta * (double)i;

const double x = xc + (radius * cos(theta));
const double y = yc + (radius * sin(theta));

half_ellipse(x, y, r2 / 2.0, r1 / 2.0, theta);
}
#if 0
int i;

Expand Down Expand Up @@ -163,3 +184,25 @@ void ellipse_foci(const double x1, const double y1, const double x2, const doubl

ellipse(x0, y0, a, b, theta);
}


void half_ellipse(const double x0, const double y0, const double a, const double b, const double theta)
{
const int npts = 36;
const double delta = M_PI / (double)npts;
const double sintheta = sin(theta);
const double costheta = cos(theta);
int i;

for (i = 0; i <= npts; i++) {
const double t = (double)i * delta;

const double x = (a * cos(t) * costheta) - (b * sin(t) * sintheta);
const double y = (a * cos(t) * sintheta) + (b * sin(t) * costheta);

if (i == 0)
moveto(x0 + x, y0 + y);
else
lineto(x0 + x, y0 + y);
}
}

0 comments on commit 6c4e59d

Please sign in to comment.