Scaling a Polygon
-
I have an application that creates hotspots for an imagemap in a asp page. It has the function to place rect, circle, and polygon(I.E. COORDS="639, 161, 671, 129, 699, 160, 669, 190") hotspot shapes. Another function on my mapping tool increases/decreases the sizes of the hotspots. This function is easy with rects and circles(increase radius or add/subtract the points on the rect), but I'm having an issue the polygon translation. I didn't want to instance the drawing class and have to convert to a in memory polygon object and translate back to a the coords... So, question is... anyone know the math to make this happen quickly? Looking for the quick fix with little overhead for my app.
-
I have an application that creates hotspots for an imagemap in a asp page. It has the function to place rect, circle, and polygon(I.E. COORDS="639, 161, 671, 129, 699, 160, 669, 190") hotspot shapes. Another function on my mapping tool increases/decreases the sizes of the hotspots. This function is easy with rects and circles(increase radius or add/subtract the points on the rect), but I'm having an issue the polygon translation. I didn't want to instance the drawing class and have to convert to a in memory polygon object and translate back to a the coords... So, question is... anyone know the math to make this happen quickly? Looking for the quick fix with little overhead for my app.
I don't know this would be useful or not (and I think you already know this!)but this is all it's math it can be done using rectangle technique and i'm think is fast enough for normal size shapes you can assume all your shapes you are going to resize are in a rectangle (x1,y1),(x2,y2) which the first one is top left and the second is bottom right so for resizing the shape you can resize the rectangle and map the changes to your shape the easiest way is to get one point as a reference inside the rectangle for fixing the shape the rectangle would be used for calculating the ratio if you get the ratio directly you wouldn't need the ectangle points for example I suppose that I have a polygon with (10,10),(21,21),(15,40) and I want to resize it to 2X (the ratio) I assume my reference point to (10,10) my new resized polygon without fixing to its position is (20,20),(42,42),(30,80) my referene point is (20,20) in new polygon so it has linear transform (10,10) from the actual reference so I must subtract it and my refDiff would be (10,10) the resized fixed position polygon would be (10,10),(32,32),(20,70) but if you dont have the ratio you must find ir from the rectangle which "x1 is Min of all x" "x2 is Max of all x" "y1 is Min of all y" and "y2 is Max of all y" you cn find the ratio from changing the first ractangle Width and Height from the second one and use the ratio as before so the formula foreach point would be Xn=ratioAtx*xn-refxDiff Yn=ratioAty*yn-refyDiff I think this is the easiest way to do that in math and implementing it is depend on yourself (sorry if you didn't mean this) hope this would be useful
-
I don't know this would be useful or not (and I think you already know this!)but this is all it's math it can be done using rectangle technique and i'm think is fast enough for normal size shapes you can assume all your shapes you are going to resize are in a rectangle (x1,y1),(x2,y2) which the first one is top left and the second is bottom right so for resizing the shape you can resize the rectangle and map the changes to your shape the easiest way is to get one point as a reference inside the rectangle for fixing the shape the rectangle would be used for calculating the ratio if you get the ratio directly you wouldn't need the ectangle points for example I suppose that I have a polygon with (10,10),(21,21),(15,40) and I want to resize it to 2X (the ratio) I assume my reference point to (10,10) my new resized polygon without fixing to its position is (20,20),(42,42),(30,80) my referene point is (20,20) in new polygon so it has linear transform (10,10) from the actual reference so I must subtract it and my refDiff would be (10,10) the resized fixed position polygon would be (10,10),(32,32),(20,70) but if you dont have the ratio you must find ir from the rectangle which "x1 is Min of all x" "x2 is Max of all x" "y1 is Min of all y" and "y2 is Max of all y" you cn find the ratio from changing the first ractangle Width and Height from the second one and use the ratio as before so the formula foreach point would be Xn=ratioAtx*xn-refxDiff Yn=ratioAty*yn-refyDiff I think this is the easiest way to do that in math and implementing it is depend on yourself (sorry if you didn't mean this) hope this would be useful
I think I have to plug my values into a matrix and scale the vectors based off of a reference point(like you said) which I'm just going to cheat and find the average of the X coords and the Y coords for that reference point. But the Matrix.Scale method doesn't support a certain reference point so i would have to extend the method and thats a pain, or i'm just lazy. But if anyone has done such a thing(scaling a 2d polygon from a reference point) please assist. Thanks!
-
I don't know this would be useful or not (and I think you already know this!)but this is all it's math it can be done using rectangle technique and i'm think is fast enough for normal size shapes you can assume all your shapes you are going to resize are in a rectangle (x1,y1),(x2,y2) which the first one is top left and the second is bottom right so for resizing the shape you can resize the rectangle and map the changes to your shape the easiest way is to get one point as a reference inside the rectangle for fixing the shape the rectangle would be used for calculating the ratio if you get the ratio directly you wouldn't need the ectangle points for example I suppose that I have a polygon with (10,10),(21,21),(15,40) and I want to resize it to 2X (the ratio) I assume my reference point to (10,10) my new resized polygon without fixing to its position is (20,20),(42,42),(30,80) my referene point is (20,20) in new polygon so it has linear transform (10,10) from the actual reference so I must subtract it and my refDiff would be (10,10) the resized fixed position polygon would be (10,10),(32,32),(20,70) but if you dont have the ratio you must find ir from the rectangle which "x1 is Min of all x" "x2 is Max of all x" "y1 is Min of all y" and "y2 is Max of all y" you cn find the ratio from changing the first ractangle Width and Height from the second one and use the ratio as before so the formula foreach point would be Xn=ratioAtx*xn-refxDiff Yn=ratioAty*yn-refyDiff I think this is the easiest way to do that in math and implementing it is depend on yourself (sorry if you didn't mean this) hope this would be useful
Very very helpful. I have impelmented it in C#, see the link: http://www.mylepaint.com/phpBB3/viewtopic.php?f=4&t=31