Go around matrices/vectors columns
Show older comments
Hi all,
If I have a point on one of a pentagon edges, say
, and I want to calculate the vectors coorindates between this point and each vertex of the polygon, i.e.,
, except the neighbouring ones as shown below:
, and I want to calculate the vectors coorindates between this point and each vertex of the polygon, i.e.,
, except the neighbouring ones as shown below:
In this case, I should have three vectors that correspond to three vertices. My question is, how to construct these vectors by looping over the vertices coordinates columns? If I'm in the first edge, then I need the second, third and fourth column of the vertices coordinates. What if the point is in the third edge? This time, I need to take the fourth, fifth, and first cooridnates. Also, what if I have a hexagon instead? I'd like to have a generalisable code that goes through the next
vertices coordinates (n here is then umber of the polygon sides) no matter where the point is in the polygon.
Here is my attempt:
%polygon vertices coordinates
Cox = [0.4540 0.9877 0.1564 -0.8910 -0.7071] ;
Coy = [-0.8910 0.1564 0.9877 0.4540 -0.7071] ;
%point coodinates
x0 = -0.4649;
y0 = -0.7455;
%the first vector
vecx1 = Cox(2) - x0;
vecy1 = Coy(2) - y0;
vec1 = [vecx1 ; vecy1]
%the second vector
vecx2 = Cox(3) - x0;
vecy2 = Coy(3) - y0;
vec2 = [vecx2 ; vecy2]
%the third vector
vecx3 = Cox(4) - x0;
vecy3 = Coy(4) - y0;
vec3 = [vecx3 ; vecy3]
Any help would be appreicted.
Accepted Answer
More Answers (0)
Categories
Find more on Creating and Concatenating Matrices in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
