-
Notifications
You must be signed in to change notification settings - Fork 1
/
rational_bezier_curves_2d.mac
91 lines (65 loc) · 2.45 KB
/
rational_bezier_curves_2d.mac
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
/*
https://github.com/t-o-k/Maxima-bezier/rational_bezier_curves_2d.mac
Copyright (c) 2020 Tor Olav Kristensen, http://subcube.com
Use of this source code is governed by the GNU Lesser General Public License version 3, which can be found in the LICENSE file.
Resources:
"Drawing CircleswithRational Quadratic Bezier Curves"
https://ctan.uib.no/macros/latex/contrib/lapdf/rcircle.pdf
"Graphics with MAXIMA"
http://www.austromath.at/daten/maxima/zusatz/Graphics_with_Maxima.pdf
*/
kill(all);
load("draw");
load("bezier");
tau: 2*%pi;
no_of_segments: 3;
angle: tau/no_of_segments/2;
r2: r1/cos(angle);
points_evn_x: r1*cos(angle*[ 0, 2, 4 ]);
points_evn_y: r1*sin(angle*[ 0, 2, 4 ]);
points_odd_x: r2*cos(angle*[ 1, 3, 5 ]);
points_odd_y: r2*sin(angle*[ 1, 3, 5 ]);
points1_x: [ points_evn_x[1], points_odd_x[1], points_evn_x[2] ];
points1_y: [ points_evn_y[1], points_odd_y[1], points_evn_y[2] ];
points2_x: [ points_evn_x[2], points_odd_x[2], points_evn_x[3] ];
points2_y: [ points_evn_y[2], points_odd_y[2], points_evn_y[3] ];
points3_x: [ points_evn_x[3], points_odd_x[3], points_evn_x[1] ];
points3_y: [ points_evn_y[3], points_odd_y[3], points_evn_y[1] ];
weights: matrix([ 1, cos(angle), 1 ]);
define(f1_x(s), rational_bezier_function_1a(matrix(points1_x), weights, s));
define(f1_y(s), rational_bezier_function_1a(matrix(points1_y), weights, s));
define(f2_x(s), rational_bezier_function_1a(matrix(points2_x), weights, s));
define(f2_y(s), rational_bezier_function_1a(matrix(points2_y), weights, s));
define(f3_x(s), rational_bezier_function_1a(matrix(points3_x), weights, s));
define(f3_y(s), rational_bezier_function_1a(matrix(points3_y), weights, s));
r1: 2;
draw2d(
title = "Circle made with 3 rational Bezier curves",
proportional_axes = xy,
xrange = [ -6, +5 ],
yrange = [ -5, +5 ],
line_width = 4,
color = red,
parametric(f1_x(s), f1_y(s), s, 0, 1),
color = green,
parametric(f2_x(s), f2_y(s), s, 0, 1),
color = blue,
parametric(f3_x(s), f3_y(s), s, 0, 1),
line_width = 2,
line_type = dashes,
point_type = none,
points_joined = true,
color = red,
points(''points1_x, ''points1_y),
color = green,
points(''points2_x, ''points2_y),
color = blue,
points(''points3_x, ''points3_y),
point_size = 2,
point_type = filled_circle,
points_joined = false,
color = black,
points(''points_evn_x, ''points_evn_y),
color = gray,
points(''points_odd_x, ''points_odd_y)
);