How do I expand / shrink a polygon with a fixed center point in MATLAB?

26 views (last 30 days)
I have a polygon drawn with the LINE(x,y) command in MATLAB, where x,y are the coordinate vectors of the points that forms this polygon.
I would like to expand or shrink the polygon by a factor A.
I would like also that the center of the polygon, which has the coordinates (mean(x),mean(y)), will be a stationary point in this transformation.

Accepted Answer

MathWorks Support Team
MathWorks Support Team on 15 Feb 2021
Edited: MathWorks Support Team on 17 Feb 2021
To calculate the coordinates of this transformation, use the following equations:
xt = A*x+(1-A)*mean(x(1:end-1))
yt = A*y+(1-A)*mean(y(1:end-1))
In this case, the center coordinate (mean(x),mean(y)) will be stationary.
Note that we actually do not use the last point in x,y vectors, since that last point is redundant to the first point, and we specify that last point for the LINE command to make our polygon closed. We should not take the same point twice into account when calculating the mean of the coordinates' vectors.
For other tasks similar to this, take a look at the following submission on the MATLAB File Exchange, which was awarded the 'MATLAB Central Pick of the Week'. There may be some functionality here which be of use:
- geom2d: Geometry library for matlab. Performs geometric computations on points, lines, circles, polygons...
  2 Comments
Michael Abboud
Michael Abboud on 2 Aug 2017
Edited: MathWorks Support Team on 17 Feb 2021
Hi Faez, I would recommend that you take a look at the following submission on the MATLAB File Exchange, which was awarded the 'MATLAB Central Pick of the Week'. There may be some functionality here which can help you achieve this task.
- geom2d: Geometry library for matlab. Performs geometric computations on points, lines, circles, polygons...
I have updated the above answer to include this link as well :)
Jan
Jan on 25 Apr 2019
Edited: Jan on 25 Apr 2019
[MOVED from flags] Zhiyu Xiao wrote on 23 Apr 2019 at 23:06
Great question, and it's not completely answered. Other methods all use a scaling factor rather than number of pixels.
[Please use flags only to inform admins and editors about inappropriate contents like rudeness or spam. Thanks.]
It is not clear, what you mean with "nor completely answered". Did you see Jin Mia's answers?

Sign in to comment.

More Answers (0)

Categories

Find more on Elementary Polygons in Help Center and File Exchange

Products

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!