Skip to content

Commit

Permalink
Make the ellipse plot more interesting by changing it to a four-secti…
Browse files Browse the repository at this point in the history
…on drawing. Only three sections currently filled with ellipse patterns. TODO: fill the fourth one.
  • Loading branch information
anachrocomputer committed Aug 27, 2020
1 parent 83f1bf3 commit 918fc54
Showing 1 changed file with 80 additions and 10 deletions.
90 changes: 80 additions & 10 deletions ellipse.c
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* ellipse --- plot a true ellipse 2011-10-08 */
/* ellipse --- plot four patterns based on ellipses 2011-10-08 */
/* Copyright (c) 2011 John Honniball, Froods Software Development */

#include <stdio.h>
Expand All @@ -7,18 +7,19 @@
#include <math.h>
#include "hpgllib.h"

void ellipse_foci(const double x1, const double y1, const double x2, const double y2, const double d);
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);


int main(int argc, char * const argv[])
{
int opt;
double xc, yc;
double w4, h4;
double r1, r2;
double maxx, maxy;
double x1, y1;
double x2, y2;
const double scale = 40.0; /* 40 plotter units per mm */
int i;

while ((opt = getopt(argc, argv, "no:p:s:t:v:")) != -1) {
switch (opt) {
Expand Down Expand Up @@ -48,6 +49,77 @@ int main(int argc, char * const argv[])
xc = maxx / 2.0;
yc = maxy / 2.0;

h4 = maxy / 4.0;
w4 = maxx / 4.0;

r1 = maxx / 5.0;
r2 = maxy / 5.0;

/* Split page into quarters */
moveto(0.0, yc);
lineto(maxx, yc);
moveto(xc, 0.0);
lineto(xc, maxy);

/* Draw four ellipse plots */
plot_ll(w4, h4, r1, r2);
plot_lr(xc + w4, h4, r1, r2);
plot_ul(w4, yc + h4, r1, r2);
plot_ur(xc + w4, yc + h4, r1, r2);

plotend();

return (0);
}


void plot_ll(const double xc, const double yc, const double r1, const double r2)
{
circle(xc, yc, r2);
ellipse(xc, yc, r1, r2, 0.0);
ellipse(xc, yc, r1 / 3.0, r2, 0.0);
}


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 */
int i;
const double delta = (2.0 * M_PI) / 8.0;
const double radius = r2 / 2.0;

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

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

ellipse(x, y, r1 / 2.0, r2 / 2.0, theta);
}
}


void plot_ul(const double xc, const double yc, const double r1, const double r2)
{
const double r3 = r1 / 2.0;
const double r4 = r2 / 2.0;

ellipse(xc, yc, r3 * sqrt(2.0), r4 * sqrt(2.0), 0.0);
ellipse(xc, yc, r1, r2, 0.0);
ellipse(xc - r3, yc, r3, r4, 0.0);
ellipse(xc, yc + r4, r3, r4, 0.0);
ellipse(xc, yc - r4, r3, r4, 0.0);
ellipse(xc + r3, yc, r3, r4, 0.0);
}


void plot_ur(const double xc, const double yc, const double r1, const double r2)
{
circle(xc, yc, r2);
#if 0
int i;

/* Draw axes and foci */
moveto(0.0, yc);
lineto(maxx, yc);
Expand All @@ -69,13 +141,11 @@ int main(int argc, char * const argv[])
/* Draw bunch of ellipses */
for (i = 0; i < 10; i++)
ellipse_foci(x1, y1, x2, y2, (110.0 + (10.0 * i)) * scale);

plotend();

return (0);
#endif
}



void ellipse_foci(const double x1, const double y1, const double x2, const double y2, const double d)
{
const double dx = x2 - x1;
Expand Down

0 comments on commit 918fc54

Please sign in to comment.