-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsplines_example.m
100 lines (76 loc) · 2.32 KB
/
splines_example.m
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
92
93
94
95
96
97
98
%% Hobby's splines, example
%
% This file demonstrates some examples of drawing Bezier curves
% in Matlab using Hobby's algorithm for choosing control points
% based on curvature and tension.
%% Simple examples
% Create a new figure:
hfig = figure(1);
set(hfig,'color',[1 1 1],'name','Spline example');
clf;
% For clarity, define points separately:
points = {...
[0 0],[1 1],[2,0],...
};
hobbysplines(points,'debug',true,'cycle',true)
% Experiment with `tension'.
% Note the default creates roughly circular plots.
points = {[1 0],[1 1],[0 1],[0 0]};
hobbysplines(points,'debug',true,'cycle',true,'offset',[3 0]);
hobbysplines(points,'debug',true,'tension',0.75,'cycle',true,'offset',[3 0],'linestyle','.');
hobbysplines(points,'debug',true,'tension',1.5 ,'cycle',true,'offset',[3 0],'linestyle','-.');
hobbysplines(points,'debug',true,'tension',2.0 ,'cycle',true,'offset',[3 0],'linestyle','--');
t = linspace(0,2*pi,30);
plot(3.5+1/sqrt(2)*cos(t),0.5+1/sqrt(2)*sin(t),'r.','MarkerSize',10)% a "real" circle
axis equal
axis off
%% Example with more points
%
% This is supposed to also test out the various possibilities of optional
% arguments.
hfig = figure(2); clf;
set(hfig,'color',[1 1 1],'name','Spline example');
points = {
{[0 0] '' 0.7 0.7}, ... 1
[0.7 0.8], ... 2
{[0.8 2] 45}, ... 3
{[1 4] '' '' 0.5}, ... 4
[0 5], ... 5
{[-1 3.5] '' 0.6 ''}, ... 6
[-0.8 2], ... 7
[-0.8 1] % 8
};
hobbysplines(points,'debug',true,'tension',2);
axis equal
axis off
%% 3D
hfig = figure(3);
set(hfig,'color',[1 1 1],'name','3D spline example');
clf; hold on
points = {...
[0 0 0],[1 1 1],[2 0 0],[1 -1 1]...
};
hobbysplines(points,'debug',true,'cycle',true);
points = {...
{[0 0 0] '' 3},...
{[1 1 1] [0 1 0] 0.75 2},...
{[2 0 0] [0 0 -1] 1},...
{[1 -1 1] '' 0.75}...
};
hobbysplines(points,'debug',true,'cycle',true,'color','red');
axis equal
view(3)
%% Outputting points
%
% Whether you want to plot the curve manually yourself, or you want to
% continue using the plots in the curve for some other purpose.
hfig = figure(4);
set(hfig,'color',[1 1 1],'name','3D spline example');
clf; hold on
points = {...
[0 0 0],[1 1 1],[2 0 0],[1 -1 1]...
};
Q = hobbysplines(points,'cycle',true,'plot',false);
plot3(Q(:,1),Q(:,2),Q(:,3),'b--','linewidth',2)
axis equal
view(3)