# Stretching algoritm in 2d

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

## Recommended Posts

Say I have a some vertices defining an objekt. I then select the objekt with a rectangular tool with four corners. When I pull a corner of this marking tool, the vertices stretch out accordingly. Can anyone help with a suitable algoritm for this? My first try was like this: vertice+ = (the movement of the four selectioncorners/ number of selectioncorners) This works with resizing of X and Y, but nothing else. Some ideas I have is use squareroot to find the length between all vertices and selectioncorners, and adjust the vertices relative to the distance to the corners. I guess most drawing programs have a function like this, but I simply can't find a suitable and fast algorithm anywhere. Any ideas? I also plan to use this for my 2d cameraclass. Think of the selection as the camera. The selection will project at the screen and some weird foolery will be accomplished while dragging the selectioncorners around. Thanks for any help!

##### Share on other sites
You could multiply the vertice by the new size relative to the old size.
You'd divide the new size by the old size and multiply that with the vertice.

##### Share on other sites
thanks, but that won't work with rotations. I cannot distort the image, just resize it. I want to be able to change the vertices around like, for example, the distort-tool in macromedia flash.

##### Share on other sites
Not sure what you what, but you want to uniformly scale some vertices?

Multiply all vertices by the same scaling factor. If you want to scale from from a particular
point, such as the center of scaling, then just subtract all vertices from it:

vertex_pt += -scale_center;
vertex_pt *= scale_factor;
vertex_pt += scale_center;

Base the scale factor on the mouse movement:
scale_factor = some_factor * (mouse_pt - anchor_pt);

##### Share on other sites
Damn, is it me, or is GameDev getting slow as hell? After I clicked the Reply button, the page took like 2 minutes to refresh.

##### Share on other sites
Heh, thanks, but that won't help either. Its the same solution that both I and Deathray submitted. It can only handle scaling, not distortion of the object.

I want to be able to stretch only one corner and have the vertices change according to it. Just like stretching out a texture by pulling a single vertice, but have the actual algoritm for the calculations of the pixelpositions.

Any other suggestions? =(

##### Share on other sites
Well, yes, that is uniform scaling (no distortion), based on what you said:

Quote:
 I cannot distort the image, just resize it.

Perhaps you should post a better description or a post a before/after picture.

##### Share on other sites
By the sounds of things roto-zooming could help you out here. It would allow for any rotation, scaling, and can easily be extended so you could move the corners independently.

Here's where I learned how to do it.

http://www.flipcode.com/archives/The_Art_of_Demomaking-Issue_10_Roto-Zooming.shtml

1. 1
2. 2
3. 3
Rutin
16
4. 4
5. 5

• 10
• 26
• 10
• 11
• 9
• ### Forum Statistics

• Total Topics
633718
• Total Posts
3013517
×