aboutsummaryrefslogtreecommitdiff
path: root/src/cmd/plot/libplot/parabola.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/parabola.c
parent6e18e03e63942f7b0912bb91d0da02fd493af0af (diff)
Add graph, plot
Diffstat (limited to 'src/cmd/plot/libplot/parabola.c')
-rw-r--r--src/cmd/plot/libplot/parabola.c32
1 files changed, 32 insertions, 0 deletions
diff --git a/src/cmd/plot/libplot/parabola.c b/src/cmd/plot/libplot/parabola.c
new file mode 100644
index 00000000..212b9c97
--- /dev/null
+++ b/src/cmd/plot/libplot/parabola.c
@@ -0,0 +1,32 @@
+#include "mplot.h"
+void parabola(double x0, double y0, double x1, double y1, double xb, double yb){
+ register double x, y, t;
+ double c0x, c0y, c1x, c1y;
+ double dt, d2, d1;
+ d1 = sqrt((xb - x0) * (xb - x0) + (yb - y0) * (yb - y0));
+ d2 = sqrt((xb - x1) * (xb - x1) + (yb - y1) * (yb - y1));
+ if (d1 <= e1->quantum || d2 <= e1->quantum) {
+ plotline(x0, y0, x1, y1);
+ return;
+ }
+ c0x = x0 + x1 - 2. * xb;
+ c1x = 2. * (xb - x0);
+ c0y = y0 + y1 - 2. * yb;
+ c1y = 2. * (yb - y0);
+ move(x0, y0);
+ dt = e1->quantum / d1;
+ dt /= e1->grade;
+ for (t = dt; t < 0.5; t += dt) {
+ x = (c0x * t + c1x) * t + x0;
+ y = (c0y * t + c1y) * t + y0;
+ vec(x, y);
+ }
+ dt = e1->quantum / d2;
+ dt /= e1->grade;
+ for (; t < 1.0; t += dt) {
+ x = (c0x * t + c1x) * t + x0;
+ y = (c0y * t + c1y) * t + y0;
+ vec(x, y);
+ }
+ vec(x1, y1);
+}