From 6c4e59d184eadb17b5b6e208347b32bdd3f09753 Mon Sep 17 00:00:00 2001 From: John Honniball Date: Fri, 11 Sep 2020 13:26:47 +0100 Subject: [PATCH] Fill upper right sub-plot and modify lower right. Add half-ellipse function. --- TODO.md | 2 +- ellipse.c | 53 ++++++++++++++++++++++++++++++++++++++++++++++++----- 2 files changed, 49 insertions(+), 6 deletions(-) diff --git a/TODO.md b/TODO.md index d361edd..0b56c1d 100644 --- a/TODO.md +++ b/TODO.md @@ -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'. diff --git a/ellipse.c b/ellipse.c index 2e9e931..65167bc 100644 --- a/ellipse.c +++ b/ellipse.c @@ -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[]) @@ -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); } } @@ -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; @@ -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); + } +}