aboutsummaryrefslogtreecommitdiff
path: root/src/cmd/plot/libplot/rarc.c
diff options
context:
space:
mode:
authorrsc <devnull@localhost>2004-04-14 19:54:10 +0000
committerrsc <devnull@localhost>2004-04-14 19:54:10 +0000
commit4314729ddef28cb619ce97d50f0968ca24c93803 (patch)
tree3abd7849a10e842a57b1fd535f8278d22a6bf132 /src/cmd/plot/libplot/rarc.c
parent6e18e03e63942f7b0912bb91d0da02fd493af0af (diff)
Add graph, plot
Diffstat (limited to 'src/cmd/plot/libplot/rarc.c')
-rw-r--r--src/cmd/plot/libplot/rarc.c44
1 files changed, 44 insertions, 0 deletions
diff --git a/src/cmd/plot/libplot/rarc.c b/src/cmd/plot/libplot/rarc.c
new file mode 100644
index 00000000..9c8ccf15
--- /dev/null
+++ b/src/cmd/plot/libplot/rarc.c
@@ -0,0 +1,44 @@
+#include "mplot.h"
+/* arc plotting routine */
+/* from x1,y1 to x2,y2 */
+/* with center xc,yc and radius rr */
+/* integrates difference equation */
+/* negative rr draws counterclockwise */
+#define PI4 0.7854
+void rarc(double x1, double y1, double x2, double y2, double xc, double yc, double rr){
+ register double dx, dy, a, b;
+ double ph, dph, rd, xnext;
+ register int n;
+ dx = x1 - xc;
+ dy = y1 - yc;
+ rd = sqrt(dx * dx + dy * dy);
+ if (rd / e1->quantum < 1.0) {
+ move(xc, yc);
+ vec(xc, yc);
+ return;
+ }
+ dph = acos(1.0 - (e1->quantum / rd));
+ if (dph > PI4)
+ dph = PI4;
+ ph=atan2((y2-yc),(x2 - xc)) - atan2(dy, dx);
+ if (ph < 0)
+ ph += 6.2832;
+ if (rr < 0)
+ ph = 6.2832 - ph;
+ if (ph < dph)
+ plotline(x1, y1, x2, y2);
+ else {
+ n = ph / dph;
+ a = cos(dph);
+ b = sin(dph);
+ if (rr < 0)
+ b = -b;
+ move(x1, y1);
+ while ((n--) >= 0) {
+ xnext = dx * a - dy * b;
+ dy = dx * b + dy * a;
+ dx = xnext;
+ vec(dx + xc, dy + yc);
+ }
+ }
+}