alirazi
alirazi

Reputation: 161

Convert polyshape to set of coordinates array

I wish to find the shortest distance between a point and a polyshape using the distancepointpolygon function from Matlab geom2d library. The distancepointpolygon function does it for polygon and therefore how can I convert any polyshape to a N-by-2 array containing vertex coordinates? I did it manually and I am looking for a general solution.

polySquare = polyshape([0 5 5 0], [10 10 15 15]);
plot(polySquare)
square = [0 10; 5 10; 5 15; 0 15];
p0 = [5 10];
distancePointPolygon(p0, square)  

Upvotes: 1

Views: 407

Answers (1)

Cris Luengo
Cris Luengo

Reputation: 60514

polySquare.Vertices should be the matrix you need:

>> polySquare = polyshape([0 5 5 0],[10 10 15 15]);
>> polySquare.Vertices

ans =

     0    10
     0    15
     5    15
     5    10

Thus you can do:

polySquare = polyshape([0 5 5 0], [10 10 15 15]);
plot(polySquare)
square = polySquare.Vertices;
p0 = [5 10];
distancePointPolygon(p0, square)

See the documentation.

Upvotes: 3

Related Questions