Skip to content

Commit f969912

Browse files
committed
add chunkerfit to guide
1 parent 65af0db commit f969912

File tree

3 files changed

+66
-0
lines changed

3 files changed

+66
-0
lines changed

chunkie/guide/guide_chunkers.m

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,3 +126,52 @@
126126

127127
saveas(figure(6),"guide_chunkers_interior.png");
128128

129+
%%
130+
% START CHUNKERFIT
131+
132+
% Sample a smooth curve at random points
133+
rng(0)
134+
n = 20;
135+
tt = sort(2*pi*rand(n,1));
136+
r = chnk.curves.bymode(tt, [2 0.5 0.2 0.7]);
137+
138+
% can pass cparams and pref structures, as in
139+
% chunkerfunc, via the opts structure
140+
% asking for splitting can be more efficient, dependent on
141+
% desired tolerance
142+
143+
% first asking for lower precision from chunkerfunc
144+
opts = [];
145+
opts.ifclosed = true;
146+
opts.cparams = [];
147+
opts.cparams.eps = 1e-3;
148+
opts.pref = [];
149+
opts.pref.k = 16;
150+
chnkr = chunkerfit(r, opts);
151+
152+
% automatically creates a chunker between each node
153+
opts.splitatpoints = true;
154+
chnkrsp = chunkerfit(r, opts);
155+
156+
% then asking for more precision from chunkerfunc
157+
opts.cparams.eps = 1e-9;
158+
opts.splitatpoints = false;
159+
chnkr2 = chunkerfit(r, opts);
160+
161+
% automatically creates a chunker between each node
162+
opts.splitatpoints = true;
163+
chnkrsp2 = chunkerfit(r, opts);
164+
165+
figure(7)
166+
clf
167+
tiledlayout(2,2,"TileSpacing","compact");
168+
nexttile; plot(chnkr,'k-x'); title(sprintf("nch = %d, eps=1e-3",chnkr.nch));
169+
hold on; plot(r(1,:),r(2,:),'bd');
170+
nexttile; plot(chnkrsp,'k-x'); title(sprintf("nch = %d, eps=1e-3\n (splitting)",chnkrsp.nch));
171+
hold on; plot(r(1,:),r(2,:),'bd');
172+
nexttile; plot(chnkr2,'k-x'); title(sprintf("nch = %d, eps=1e-9",chnkr2.nch));
173+
hold on; plot(r(1,:),r(2,:),'bd');
174+
nexttile; plot(chnkrsp2,'k-x'); title(sprintf("nch = %d, eps=1e-9\n (splitting)",chnkrsp2.nch));
175+
hold on; plot(r(1,:),r(2,:),'bd');
176+
% END CHUNKERFIT
177+
saveas(figure(7),"guide_chunkers_chunkerfit.png");
41 KB
Loading

docs/guide/chunkers.rst

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,21 @@ parameterized curves:
6868

6969
|pic1| |pic2|
7070

71+
For a given set of points, a spline curve can be fit to them and
72+
discretized as a chunker using `chunkerfit`:
73+
74+
.. include:: ../../chunkie/guide/guide_chunkers.m
75+
:literal:
76+
:code: matlab
77+
:start-after: % START CHUNKERFIT
78+
:end-before: % END CHUNKERFIT
79+
80+
.. image:: ../../chunkie/guide/guide_chunkers_chunkerfit.png
81+
:width: 500px
82+
:alt: circle chunker
83+
:align: center
84+
85+
7186
Given a set of vertices, a rounded polygon can be defined:
7287

7388
.. include:: ../../chunkie/guide/guide_chunkers.m
@@ -81,6 +96,8 @@ Given a set of vertices, a rounded polygon can be defined:
8196
:alt: circle chunker
8297
:align: center
8398

99+
100+
84101

85102
Working with Chunkers
86103
----------------------

0 commit comments

Comments
 (0)