Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. Scaling a Polygon

Scaling a Polygon

Scheduled Pinned Locked Moved C#
helpquestiongraphicsperformance
4 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • J Offline
    J Offline
    Joshua Lunsford
    wrote on last edited by
    #1

    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.

    H 1 Reply Last reply
    0
    • J Joshua Lunsford

      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.

      H Offline
      H Offline
      Hessam Jalali
      wrote on last edited by
      #2

      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

      J L 2 Replies Last reply
      0
      • H Hessam Jalali

        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

        J Offline
        J Offline
        Joshua Lunsford
        wrote on last edited by
        #3

        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!

        1 Reply Last reply
        0
        • H Hessam Jalali

          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

          L Offline
          L Offline
          Lewis Liu L
          wrote on last edited by
          #4

          Very very helpful. I have impelmented it in C#, see the link: http://www.mylepaint.com/phpBB3/viewtopic.php?f=4&t=31

          1 Reply Last reply
          0
          Reply
          • Reply as topic
          Log in to reply
          • Oldest to Newest
          • Newest to Oldest
          • Most Votes


          • Login

          • Don't have an account? Register

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • World
          • Users
          • Groups