MATLAB Answers

0

Create coordinates on a convex hull

Asked by Kwek Lawrence on 12 Sep 2019
Latest activity Edited by Bruno Luong
on 12 Sep 2019
I have a convex hull, defined by
k=convhull(x,y)
P=[x(k),y(k)]
kS=polyshape(P)
kP=perimeter(kShape)
How can I divide the perimeter of the convex hull into n (e.g. 500) equal distance/lengths, and find the respective coordinates?

  0 Comments

Sign in to comment.

2 Answers

Answer by Bruno Luong
on 12 Sep 2019
Edited by Bruno Luong
on 12 Sep 2019
 Accepted Answer

% test data
xy=rand(100,2);
P=xy(convhull(xy),:);
d=[0;cumsum(sqrt(sum(diff(P).^2,2)))];
xyi=interp1(d,P,linspace(0,d(end),501)); % first point ~= last point
plot(P(:,1),P(:,2),'or',xyi(:,1),xyi(:,2),'b.-');

  0 Comments

Sign in to comment.


Answer by Bjorn Gustavsson on 12 Sep 2019

Perhaps this function is overkill, but to me it seems as if this FEX-contribution should help:
xy2sn, I don't know if it is the functionality of xy2sn or the sn2xy that most resembles your request.
Perhaps either of these contributions solves your problem better:
arclength, interparc. But one of these should get you at least 90% of the way.
HTH

  0 Comments

Sign in to comment.