Results 1 to 20 of 20

Thread: RESOLVED [2.0] Scale a graphics path

  1. #1

    Thread Starter
    Fanatic Member
    Join Date
    May 2004
    Location
    england
    Posts
    598

    Resolved RESOLVED [2.0] Scale a graphics path

    Hi All,

    I know that you can use the scale(Matrix) to rezise a graphics path but when I use it the X cooridinate changes and so does the Y cooridinate, How can I get my scaling so that if the X cooridinate stays at 10 and the Y cooridinate stays at 10 but the width and height change to what ever I need?

    Thanks

    Loftty
    Last edited by loftty; Jul 28th, 2006 at 05:38 AM.

  2. #2
    type Woss is new Grumpy; wossname's Avatar
    Join Date
    Aug 2002
    Location
    #!/bin/bash
    Posts
    5,682

    Re: [2.0] Scale a graphics path

    Basically, for each coordinate of each point in your graphics path, that coordinate is multiplied by the scale value you give it.

    Sounds like you have designed a path that is not centred around 0,0.

    This is tricky to explain so i'll draw it...

    If you design a graphicspath with 0,0 completely outside your shape then when you scale it the whole shape will appear to move off to one side. However if you design it with 0,0 inside the shape then the shape will just get larger when you scale it and it won't move off to one side.

    This is an over simple way to describe it but you get what I mean.

    If you were to design a hand for a clockface for example, then you'd make sure that your design had 0,0, at the pivot-point of the design. then you can simply rotate (and/or scale) the GP and it will behave just like a clock hand and will not drift off centre.
    Attached Images Attached Images  
    Last edited by wossname; Jul 20th, 2006 at 06:53 AM.
    I don't live here any more.

  3. #3

    Thread Starter
    Fanatic Member
    Join Date
    May 2004
    Location
    england
    Posts
    598

    Re: [2.0] Scale a graphics path

    Hi,

    Thanks for the Relply, Could you give me a quick sample of how to get the centre inside the graphics path please?

    Thanks

    Loftty

  4. #4
    type Woss is new Grumpy; wossname's Avatar
    Join Date
    Aug 2002
    Location
    #!/bin/bash
    Posts
    5,682

    Re: [2.0] Scale a graphics path

    Its not something tha I can give you a sample of really. All you need to do is alter the coordinates of your original shape. Can you post the portion of your code where you are adding shapes to your graphics path? Then Ii can give you a hint as to how to alter it.
    I don't live here any more.

  5. #5

    Thread Starter
    Fanatic Member
    Join Date
    May 2004
    Location
    england
    Posts
    598

    Re: [2.0] Scale a graphics path

    Hi,

    I am not at my computer at the mo but I do have another question if that is ok, do you know some where I can get hold of lots of shapes? also is it possible to create a circle with a gradient backcolor and inside that circle have another circle that is white?

    Thanks for you help so far, I will post an example of my code when I get home.

    Thanks

    Loftty

  6. #6

    Thread Starter
    Fanatic Member
    Join Date
    May 2004
    Location
    england
    Posts
    598

    Re: [2.0] Scale a graphics path

    Hi,

    I have found out the answer to my last questions.

    Here Is my code when I am adding a rectangle

    Code:
    rect = new Rectangle(50, 50, 30, 30);
    gra.AddRectangle(rect);
    I know how to get the centre of the rectangle as I use it to rotate the shape but cannot see how I would use the centre to scale my shape.

    Thanks

    Loftty

  7. #7
    type Woss is new Grumpy; wossname's Avatar
    Join Date
    Aug 2002
    Location
    #!/bin/bash
    Posts
    5,682

    Re: [2.0] Scale a graphics path

    When you scale that ractangle, ALL 4 corners are scaled, meaning that the top-left corner will move away from 0,0.

    if you use Scale(3, 2) then your rectangle will end up at (150, 100, 90, 60)

    ((3*50) = 150
    (2*50) = 100
    (3*width) = 90
    (2*height) = 60)

    The thing is that you should not define your shape to be at any particular location when you are designing it. It should be at or around 0,0, because then you will be able to translate it and scale it without any special maths to rectify the problems you are having.

    I would suggest you use new rectangle(-15, -15, 30, 30) Because this straddles the rectangle exactly over 0,0 and thus you can rotate and scale and translate easily before you draw it in its new location.
    I don't live here any more.

  8. #8
    type Woss is new Grumpy; wossname's Avatar
    Join Date
    Aug 2002
    Location
    #!/bin/bash
    Posts
    5,682

    Re: [2.0] Scale a graphics path

    try this on an empty form with a button in the top right of the form....
    Code:
    			GraphicsPath gp = new GraphicsPath();
    			gp.AddRectangle( new Rectangle( -15, -15, 30, 30 ) );
    
    			this.CreateGraphics().DrawPath( new Pen( Color.Blue, 3 ), gp );
    
    			Matrix m = new Matrix();
    			m.Translate( 100, 100 );
    			m.Scale( 2, 2 );
    			m.Rotate( 20 );
    			gp.Transform( m );
    
    			this.CreateGraphics().DrawPath( new Pen( Color.Red, 3 ), gp );
    I don't live here any more.

  9. #9

    Thread Starter
    Fanatic Member
    Join Date
    May 2004
    Location
    england
    Posts
    598

    Re: [2.0] Scale a graphics path

    Hi,

    I can see what you mean, but what happens when I do move the position of the shape to a new location of 50,50, and how would I do it on a shape like the polygon image you attached?

    Thanks

    Loftty
    Last edited by loftty; Jul 24th, 2006 at 11:53 AM.

  10. #10
    type Woss is new Grumpy; wossname's Avatar
    Join Date
    Aug 2002
    Location
    #!/bin/bash
    Posts
    5,682

    Re: [2.0] Scale a graphics path

    Normally when you want to draw many copies of a shape you'd translate() it with a matrix object, then draw it, then reset it. Then repeat this for each location you want to draw the shape at.
    I don't live here any more.

  11. #11

    Thread Starter
    Fanatic Member
    Join Date
    May 2004
    Location
    england
    Posts
    598

    Re: [2.0] Scale a graphics path

    Hi,

    I do really appriciate your help so far, but I am still not able to scale a graphics path could you give me a example of a polygon shape that is not 0,0 location and the scale changes to the value of a trackbars value?

    Thanks again,

    Loftty

  12. #12
    type Woss is new Grumpy; wossname's Avatar
    Join Date
    Aug 2002
    Location
    #!/bin/bash
    Posts
    5,682

    Re: [2.0] Scale a graphics path

    You don't ask for much do you

    Check out the image I attached. It shows you how I defined the shape using 0,0 as the scale origin.

    Run the app and then start playing with the scrollbars
    Attached Images Attached Images  
    Attached Files Attached Files
    I don't live here any more.

  13. #13

    Thread Starter
    Fanatic Member
    Join Date
    May 2004
    Location
    england
    Posts
    598

    Re: [2.0] Scale a graphics path

    Hi,

    Thanks for that, it was most helpful, I have have been having a good play with it and am getting some good results, Thank you.

    In this part of the code when I rotate it rotates the path from the top left hand corner, how can I get it to rotate from the center of the path, maybe I'm just missing a small thing here.

    Code:
    PointF center = new PointF((int)temp.GetBounds().X + ((int)temp.GetBounds().Width / 2), (int)temp.GetBounds().Y + ((int)temp.GetBounds().Height / 2));
    			//we'll be drawing the shape in the middle of the picture box...
                m.Translate((int)_myShape.GetBounds().X + ((int)_myShape.GetBounds().Width ) >> 1, (int)_myShape.GetBounds().Y + ((int)_myShape.GetBounds().Height ) >> 1);
                m.RotateAt(rotation, center);
                m.Scale(scaleWidth, scaleHeight);
                temp.Transform(m);
                drawPaths();
    Thanks

    Loftty

  14. #14
    type Woss is new Grumpy; wossname's Avatar
    Join Date
    Aug 2002
    Location
    #!/bin/bash
    Posts
    5,682

    Re: [2.0] Scale a graphics path

    Look at the image I attached. Look at how I defined the shape... 0,0 lies in the centre (more or less) of the arrowhead. That means it looks like it is spinning around on the spot.

    OR...

    You can just apply a one-time translation to your path before you store it safely away, make that translation move your shape so that it lies all around 0,0 and not just to the south-east of it. (in other words translate(-halfwidth, -halfheight);)
    I don't live here any more.

  15. #15
    type Woss is new Grumpy; wossname's Avatar
    Join Date
    Aug 2002
    Location
    #!/bin/bash
    Posts
    5,682

    Re: [2.0] Scale a graphics path

    Better get some reps for this thread.
    I don't live here any more.

  16. #16

    Thread Starter
    Fanatic Member
    Join Date
    May 2004
    Location
    england
    Posts
    598

    Re: [2.0] Scale a graphics path

    Hi,

    I have managed to rotate the path from the center of the shape, I have one more question or problem, if you have a look at the project and hit drawshape then rotate it the shape rotates fine but when I change the width or height the shapes looks more like it gets skewed, This could be right but I dont know if it is or not.

    And if I create an ellipse it does not seem to rotate.

    Thanks

    Loftty

    ps. what do you mean by reps
    Attached Files Attached Files

  17. #17
    type Woss is new Grumpy; wossname's Avatar
    Join Date
    Aug 2002
    Location
    #!/bin/bash
    Posts
    5,682

    Re: [2.0] Scale a graphics path

    You were making things too complicated due to you not defining your rectangle in the right place. This is what I mean about your coordinates in the AddRectangle() call.

    I've deleted some of the unnecessary code and altered your rectangle so that 0,0 is in the centre of the shape.

    If you have your shape eccentric with regard to 0,0 then any scaling will tend to look weird.
    Attached Files Attached Files
    I don't live here any more.

  18. #18

    Thread Starter
    Fanatic Member
    Join Date
    May 2004
    Location
    england
    Posts
    598

    Resolved RESOLVED [2.0] Scale a graphics path

    Hi,

    I have got it working now, Thank you so much for all you help over the last couple of days, if there is any way of repaying you I would.

    Thanks again

    Loftty

  19. #19
    type Woss is new Grumpy; wossname's Avatar
    Join Date
    Aug 2002
    Location
    #!/bin/bash
    Posts
    5,682

    Re: RESOLVED [2.0] Scale a graphics path



    I don't live here any more.

  20. #20
    type Woss is new Grumpy; wossname's Avatar
    Join Date
    Aug 2002
    Location
    #!/bin/bash
    Posts
    5,682

    Re: RESOLVED [2.0] Scale a graphics path

    You are very welcome.
    I don't live here any more.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width