Draw a hand using splines (Matlab)

I am trying to write a script so that I can put my hand on the screen, click a few dots with ginput and create a matlab outline of people's hands using splines. However, I’m completely not sure how you can connect splines to points that arise from your clicks, since they, of course, are described by some kind of parameterization. How can you use the spline command built into matlab when dots should not connect from left to right?

The code that I still have is small, it just creates a window and allows you to click a few dots

FigHandle = figure('Position', [15,15, 1500, 1500]);
rectangle('Position',[0,0,40,40])
daspect([1,1,1])
[x,y] = ginput;

So, I suppose my question is really what to do with x and y so that you can plan them so that they are linked “chronologically”. (And, in the end, connecting the latter to the first)

+4
source share
3 answers

look into cscvn function

curve = cscvn(points) 

returns a parametric variational or natural cubic spline curve (in ppform) passing through a given sequence of points (: j), j = 1: end.

Great example: http://www.mathworks.com/help/curvefit/examples/constructing-spline-curves-in-2d-and-3d.html

+4
source

I found an alternative to use the cscvn function.

sem-arclength, x y :

diffx = diff(x);
diffy = diff(y);
t = zeros(1,length(x)-1);
for n = 1:length(x)-1 
    t(n+1) = t(n) + sqrt(diffx(n).^2+diffy(n).^2);
end
tj = linspace(t(1),t(end),300);

xj = interp1(t,x,tj,'spline');
yj = interp1(t,y,tj,'spline');
plot(x,y,'b.',xj,yj,'r-')

.

, . , (x, y) t. t, , . interp1, x y, t, ti.

+3

, , : 2D-, . , plot(x,y).

The idea in this article is to iterate over each consecutive pair of points and interpolate between these points. Perhaps you can adapt this to work with splines, you need to give 4 points each time, although this can cause problems, as they can go back.

To connect the beginning and the end, just do this before interpolation:

x(end+1) = x(1);
y(end+1) = y(1);
+1
source

Source: https://habr.com/ru/post/1531782/


All Articles