# Move side of a polygon

This topic is 1115 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

I am building a level editor for my game and doing the implementation for resizing (moving of two vectors by a given delta) of polygons right now. Grabing the side of a polygon and moving the vertices along the given delta works already, so the only problem i have right now is to doing the repositioning so that the body center match the new local center.

How do i calculate the new body center and delta for offseting my local vertices?

See picture for better understanding:

##### Share on other sites

Wouldn't this be simply movedelta / 2?

##### Share on other sites

The easiest way I can think of is the following:

First, compute the new vertex positions in global space (affected vertices + delta). After that just sum them up and divide by vertex count to obtain the center of mass (this is a nifty trick to compute the center of something). You can compute local vertex positions by <global vertex position> - <center of mass> (all this does is shift the center of mass to the origin, which is the local coordinate system in question).

The nice thing is that this works for an arbitrary number of vertices!

For rectangular regions you can calculate Lactose!'s solution analytically, but I don't think it's worth the hassle, unless you have want to see the math.

##### Share on other sites

Yeah it was delta / 2, first move the local vertices for the desired side by the full delta - than move back every local vertex by delta / 2 and then move the body position by delta / 2 too.

But the solution from duckflock i like much more, because it will preserve the center of mass - i will give it a try ;-)

Now it is getting more complex because i want to support scaling for non-rectangulary sides too, in this case you must scale the the other two sides connected too (based on the angle between).

And much more to come:

- Extruding

- Single vertex moving

Edited by Finalspace

1. 1
2. 2
Rutin
21
3. 3
A4L
15
4. 4
5. 5

• 13
• 26
• 10
• 11
• 44
• ### Forum Statistics

• Total Topics
633740
• Total Posts
3013621
×