Skip to content

Commit dc400fa

Browse files
Change 'arches' into a four sub-plot drawing. Make it scale properly and draw the actual arches twice to show the thickness of the imposts and voussoirs.
1 parent f565106 commit dc400fa

File tree

1 file changed

+89
-61
lines changed

1 file changed

+89
-61
lines changed

arches.c

Lines changed: 89 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -7,18 +7,22 @@
77
#include <math.h>
88
#include "hpgllib.h"
99

10-
void circulararch(const double x0, const double y0, const double width, const double height, const double r);
11-
void threecentredarch(const double x0, const double y0, const double width, const double height, const double d, const double r1);
12-
void ellipticalarch(const double x0, const double y0, const double width, const double height, const double a, const double b);
10+
void plot_ur(const double x0, const double y0, const double width, const double height, const double r1, const double r2);
11+
void circulararch(const double xc, const double y0, const double yc, const double r);
12+
void plot_ll(const double x0, const double y0, const double width, const double height, const double r1, const double r2);
13+
void ellipticalarch(const double xc, const double y0, const double yc, const double a, const double b);
14+
void plot_ul(const double x0, const double y0, const double width, const double height, const double r1, const double r2);
15+
void threecentredarch(const double xc, const double y0, const double yc, const double d, const double r);
1316
void half_ellipse(const double x0, const double y0, const double a, const double b, const double theta);
17+
void plot_lr(const double x0, const double y0, const double width, const double height, const double r1, const double r2);
1418

1519

1620
int main(int argc, char * const argv[])
1721
{
1822
int opt;
1923
double maxx, maxy;
20-
double xcell;
21-
double ycell;
24+
double xc, yc;
25+
double r1, r2;
2226

2327
while ((opt = getopt(argc, argv, "no:p:s:t:v:")) != -1) {
2428
switch (opt) {
@@ -45,34 +49,31 @@ int main(int argc, char * const argv[])
4549

4650
getplotsize(&maxx, &maxy);
4751

48-
xcell = maxx / 3.0;
49-
ycell = maxy / 2.0;
52+
xc = maxx / 2.0;
53+
yc = maxy / 2.0;
5054

51-
/* Divide page into six boxes */
52-
moveto(0.0, ycell);
53-
lineto(maxx, ycell);
55+
r1 = maxx / 5.0;
56+
r2 = maxy / 5.0;
5457

55-
moveto(xcell, 0.0);
56-
lineto(xcell, maxy);
58+
/* Split page into quarters */
59+
moveto(0.0, yc);
60+
lineto(maxx, yc);
61+
moveto(xc, 0.0);
62+
lineto(xc, maxy);
5763

58-
moveto(xcell * 2.0, maxy);
59-
lineto(xcell * 2.0, 0.0);
64+
/* Draw four arch plots */
65+
plot_ll(0.0, 0.0, xc, yc, r1, r2);
66+
plot_lr(xc, 0.0, xc, yc, r1, r2);
67+
plot_ul(0.0, yc, xc, yc, r1, r2);
68+
plot_ur(xc, yc, xc, yc, r1, r2);
6069

61-
circulararch(xcell, ycell, xcell, ycell, 50.0);
62-
63-
ellipticalarch(0.0, 0.0, xcell, ycell, 50.0, 35.0);
64-
65-
threecentredarch(0.0, ycell, xcell, ycell, 30.0, 20.0);
66-
67-
// threecentredarch(xcell, 0.0, xcell, ycell, 33.0, 22.0);
68-
6970
plotend();
7071

7172
return (0);
7273
}
7374

7475

75-
void circulararch(const double x0, const double y0, const double width, const double height, const double r)
76+
void plot_ur(const double x0, const double y0, const double width, const double height, const double r1, const double r2)
7677
{
7778
const double xc = x0 + (width / 2.0);
7879
const double yc = y0 + (height / 2.0);
@@ -84,27 +85,36 @@ void circulararch(const double x0, const double y0, const double width, const do
8485
lineto(xc, y0 + height);
8586

8687
/* Circle forming arch, drawn as full circle */
87-
circle(xc, yc, r * 40.0);
88+
circle(xc, yc, r2);
8889

8990
/* Thicker pen for outline of arch */
9091
// pencolr(1);
9192
// printf("VS5;\n");
9293

93-
moveto(xc - (r * 40.0), y0);
94-
lineto(xc - (r * 40.0), yc);
94+
circulararch(xc, y0, yc, r2);
95+
circulararch(xc, y0, yc, r2 * 1.15);
96+
}
97+
98+
99+
void circulararch(const double xc, const double y0, const double yc, const double r)
100+
{
101+
moveto(xc - r, y0);
102+
lineto(xc - r, yc);
95103

96104
/* The arch itself, a half circle */
97105
arc(xc, yc, -180.0);
98106

99-
lineto(xc + (r * 40.0), y0);
107+
lineto(xc + r, y0);
100108
}
101109

102110

103-
void threecentredarch(const double x0, const double y0, const double width, const double height, const double d, const double r1)
111+
void plot_ul(const double x0, const double y0, const double width, const double height, const double r1, const double r2)
104112
{
105-
/* d: Distance from central axis to centre of smaller arcs */
106-
/* r1: Radius of smaller arcs */
107-
const double r2 = sqrt((d * d) + (d * d)) + r1; /* Radius of larger arc */
113+
/* r3: Distance from central axis to centre of smaller arcs */
114+
/* r4: Radius of smaller arcs */
115+
const double r3 = r1 / 2.0;
116+
const double r4 = r2 / 2.0;
117+
const double r5 = sqrt((r3 * r3) + (r3 * r3)) + r4; /* Radius of larger arc */
108118
const double xc = x0 + (width / 2.0);
109119
const double yc = y0 + (height / 2.0);
110120

@@ -115,51 +125,59 @@ void threecentredarch(const double x0, const double y0, const double width, cons
115125
lineto(xc, y0 + height);
116126

117127
/* LH centre mark */
118-
moveto(xc - (d * 40.0), yc + (3.0 * 40.0));
119-
lineto(xc - (d * 40.0), yc - (3.0 * 40.0));
128+
moveto(xc - r3, yc + (3.0 * 40.0));
129+
lineto(xc - r3, yc - (3.0 * 40.0));
120130

121131
/* LH small circle */
122-
circle(xc - (d * 40.0), yc, r1 * 40.0);
132+
circle(xc - r3, yc, r4);
123133

124134
/* RH centre mark */
125-
moveto(xc + (d * 40.0), yc + (3.0 * 40.0));
126-
lineto(xc + (d * 40.0), yc - (3.0 * 40.0));
135+
moveto(xc + r3, yc + (3.0 * 40.0));
136+
lineto(xc + r3, yc - (3.0 * 40.0));
127137

128138
/* RH small circle */
129-
circle(xc + (d * 40.0), yc, r1 * 40.0);
139+
circle(xc + r3, yc, r4);
130140

131141
/* 45 degree construction lines */
132-
moveto(xc - (2.0 * d * 40.0), yc + (d * 40.0));
133-
lineto(xc, yc - (d * 40.0));
134-
lineto(xc + (2.0 * d * 40.0), yc + (d * 40.0));
142+
moveto(xc - (2.0 * r3), yc + r3);
143+
lineto(xc, yc - r3);
144+
lineto(xc + (2.0 * r3), yc + r3);
135145

136146
/* Bottom centre mark */
137-
moveto(xc - (3.0 * 40.0), yc - (d * 40.0));
138-
lineto(xc + (3.0 * 40.0), yc - (d * 40.0));
147+
moveto(xc - (3.0 * 40.0), yc - r3);
148+
lineto(xc + (3.0 * 40.0), yc - r3);
139149

140150
/* Upper large circle, only drawn as half-circle */
141-
moveto(xc + (r2 * 40.0), yc - (d * 40.0));
142-
arc(xc, yc - (d * 40.0), 180.0);
151+
moveto(xc + r5, yc - r3);
152+
arc(xc, yc - r3, 180.0);
143153

144154
/* Thicker pen for outline of arch */
145155
// pencolr(1);
146156
// printf("VS5;\n");
147157

148-
moveto(xc - ((d + r1) * 40.0), y0);
149-
lineto(xc - ((d + r1) * 40.0), yc);
158+
threecentredarch(xc, y0, yc, r3, r4);
159+
threecentredarch(xc, y0, yc, r3, r4 * 1.3);
160+
}
161+
150162

151-
arc(xc - (d * 40.0), yc, -45.0);
152-
arc(xc, yc - (d * 40.0), -90.0);
153-
arc(xc + (d * 40.0), yc, -45.0);
163+
void threecentredarch(const double xc, const double y0, const double yc, const double d, const double r)
164+
{
165+
moveto(xc - (d + r), y0);
166+
lineto(xc - (d + r), yc);
167+
168+
arc(xc - d, yc, -45.0);
169+
arc(xc, yc - d, -90.0);
170+
arc(xc + d, yc, -45.0);
154171

155-
lineto(xc + ((d + r1) * 40.0), y0);
172+
lineto(xc + (d + r), y0);
156173
}
157174

158175

159-
void ellipticalarch(const double x0, const double y0, const double width, const double height, const double a, const double b)
176+
void plot_ll(const double x0, const double y0, const double width, const double height, const double r1, const double r2)
160177
{
161178
const double xc = x0 + (width / 2.0);
162179
const double yc = y0 + (height / 2.0);
180+
const double thickness = r1 / 10.0;
163181

164182
/* Centre lines */
165183
moveto(x0, yc);
@@ -168,41 +186,51 @@ void ellipticalarch(const double x0, const double y0, const double width, const
168186
lineto(xc, y0 + height);
169187

170188
/* Ellipse forming arch, drawn in full */
171-
ellipse(xc, yc, a * 40.0, b * 40.0, 0.0);
189+
ellipse(xc, yc, r1, r2, 0.0);
172190

173191
/* Thicker pen for outline of arch */
174192
// pencolr(1);
175193
// printf("VS5;\n");
176194

177-
moveto(xc + (a * 40.0), y0);
178-
lineto(xc + (a * 40.0), yc);
195+
ellipticalarch(xc, y0, yc, r1, r2);
196+
ellipticalarch(xc, y0, yc, r1 + thickness, r2 + thickness);
197+
}
198+
199+
200+
void ellipticalarch(const double xc, const double y0, const double yc, const double a, const double b)
201+
{
202+
moveto(xc + a, y0);
203+
lineto(xc + a, yc);
179204

180205
/* The arch itself, a half ellipse */
181-
half_ellipse(xc, yc, a * 40.0, b * 40.0, 0.0);
206+
half_ellipse(xc, yc, a, b, 0.0);
182207

183-
lineto(xc - (a * 40.0), y0);
208+
lineto(xc - a, y0);
184209
}
185210

186211

187212
void half_ellipse(const double x0, const double y0, const double a, const double b, const double theta)
188213
{
189214
const int npts = 36;
190-
double t;
191215
const double delta = M_PI / (double)npts;
192216
const double sintheta = sin(theta);
193217
const double costheta = cos(theta);
194-
double x, y;
195218
int i;
196219

197220
for (i = 0; i <= npts; i++) {
198-
t = (double)i * delta;
221+
const double t = (double)i * delta;
199222

200-
x = (a * cos(t) * costheta) - (b * sin(t) * sintheta);
201-
y = (a * cos(t) * sintheta) + (b * sin(t) * costheta);
223+
const double x = (a * cos(t) * costheta) - (b * sin(t) * sintheta);
224+
const double y = (a * cos(t) * sintheta) + (b * sin(t) * costheta);
202225

203226
if (i == 0)
204227
moveto(x0 + x, y0 + y);
205228
else
206229
lineto(x0 + x, y0 + y);
207230
}
208231
}
232+
233+
234+
void plot_lr(const double x0, const double y0, const double width, const double height, const double r1, const double r2)
235+
{
236+
}

0 commit comments

Comments
 (0)