dcsimg
Results 1 to 9 of 9

Thread: [RESOLVED] My Graphics appear upside down?

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Jan 2013
    Posts
    177

    Resolved [RESOLVED] My Graphics appear upside down?

    Hey,

    I have been playing with the graphics class in vb.net and for some reason everything I draw appears upside down.

    Here are the co-ordinates going in

    From: X - 338 Y - 581 To: X - 338 Y - 564
    From: X - 338 Y - 564 To: X - 338 Y - 564
    From: X - 338 Y - 564 To: X - 389 Y - 564
    From: X - 389 Y - 564 To: X - 394 Y - 564
    From: X - 394 Y - 564 To: X - 394 Y - 611
    From: X - 394 Y - 611 To: X - 394 Y - 616
    From: X - 394 Y - 616 To: X - 335 Y - 616
    From: X - 335 Y - 616 To: X - 335 Y - 616
    From: X - 335 Y - 616 To: X - 335 Y - 603

    Code:
      g.DrawLine(New Pen(newColor, size), x_loc(k), y_loc(k), x_loc(k + 1), y_loc(k + 1))
                            Console.WriteLine("From: X - " & x_loc(k) & " Y - " & y_loc(k) & " To: X - " & x_loc(k + 1) & " Y - " & y_loc(k + 1))
    This is what I end up with

    Name:  DETE.JPG
Views: 120
Size:  5.7 KB

    And while typing this I figured out what could be wrong!!

    I am guessing my origin for the drawing is set to the top leftcorner of the picture box I am drawing in, is it possible to change the origin to the bottom left corner?
    Last edited by Crzyrio; Apr 25th, 2013 at 03:26 PM.

  2. #2
    Super Moderator dday9's Avatar
    Join Date
    Mar 2011
    Location
    South Louisiana
    Posts
    9,544

    Re: My Graphics appear upside down?

    In vb.net the way that points work is: imagine for a second two arrows starting at the same location, one going vertically, the other going horizontally. Point(0, 0) would be where the two points meet. If x is anything greater than 0 then you're going to the right, if y is anything greater than 0 then you're going down. Take a look at this picture:
    Name:  point.png
Views: 88
Size:  2.4 KB

    So y - 581 to y - 564 will be going from down to up 17 pixels and x - 338 to x - 389 will go left to right 51 pixels.
    Last edited by dday9; Apr 25th, 2013 at 03:43 PM. Reason: 'to arrows' is not the same as 'two arrows'!

  3. #3
    Super Moderator Shaggy Hiker's Avatar
    Join Date
    Aug 2002
    Location
    Idaho
    Posts
    34,323

    Re: My Graphics appear upside down?

    That's not just VB, that's ALL computer graphics. For whatever reason, graphics in computers have always had the origin in the upper left corner. It may be because that is where there onld CRT scan began, but whatever the reason, it has been that way forever. Fighting against the convention is pretty hopeless. One thing you can do is translate all your points, but that would mean a calculation for each point (albeit a very simple one). Easier would be to just recognize that the origin is the upper left corner and live with it. You will notice that all controls work that way, as well.
    My usual boring signature: Nothing

  4. #4
    PowerPoster dunfiddlin's Avatar
    Join Date
    Jun 2012
    Posts
    8,242

    Re: My Graphics appear upside down?

    It may be because that is where there onld CRT scan began
    Well possibly, but more to the point it's not a graph! It's just Western scanning logic. You start a page at the top left corner and progress toward the bottom right. If the Arab world had been at the forefront of electronics it could just as easily be top right that's 0,0 by convention. Lord only knows how we'd have coped if boustrophedon was the predominant reading method though!
    As the 6-dimensional mathematics professor said to the brain surgeon, "It ain't Rocket Science!"

    Reviews: "dunfiddlin likes his DataTables" - jmcilhinney

    Please be aware that whilst I will read private messages (one day!) I am unlikely to reply to anything that does not contain offers of cash, fame or marriage!

  5. #5

    Thread Starter
    Addicted Member
    Join Date
    Jan 2013
    Posts
    177

    Re: My Graphics appear upside down?

    Quote Originally Posted by dday9 View Post
    In vb.net the way that points work is: imagine for a second two arrows starting at the same location, one going vertically, the other going horizontally. Point(0, 0) would be where the two points meet. If x is anything greater than 0 then you're going to the right, if y is anything greater than 0 then you're going down. Take a look at this picture:
    Name:  point.png
Views: 88
Size:  2.4 KB

    So y - 581 to y - 564 will be going from down to up 17 pixels and x - 338 to x - 389 will go left to right 51 pixels.
    Thanks for the explanation
    I have been trying to figure this out for a while lol

    Quote Originally Posted by Shaggy Hiker View Post
    That's not just VB, that's ALL computer graphics. For whatever reason, graphics in computers have always had the origin in the upper left corner. It may be because that is where there onld CRT scan began, but whatever the reason, it has been that way forever. Fighting against the convention is pretty hopeless. One thing you can do is translate all your points, but that would mean a calculation for each point (albeit a very simple one). Easier would be to just recognize that the origin is the upper left corner and live with it. You will notice that all controls work that way, as well.
    Besides translating all my points, is it possible to flip the image?
    These points are pulled straight from another program that my application talks too.

  6. #6
    Powered By Medtronic dbasnett's Avatar
    Join Date
    Dec 2007
    Location
    Pointless Forest 38.517,-92.023
    Posts
    9,227

    Re: My Graphics appear upside down?

    My First Computer -- Documentation Link (RT?M) -- Using the Debugger -- Prime Number Sieve
    Counting Bits -- Subnet Calculator -- UI Guidelines -- >> SerialPort Answer <<

    "Those who use Application.DoEvents have no idea what it does and those who know what it does never use it." John Wein

  7. #7
    Super Moderator si_the_geek's Avatar
    Join Date
    Jul 2002
    Location
    Bristol, UK
    Posts
    41,267

    Re: My Graphics appear upside down?

    To just flip the Y position, it's as simple as doing this for each point:
    Code:
    NewY = DisplayAreaHeight - OriginalY
    While using methods like RotateFlip may be slightly easier (assuming you pick the right parameters first time), they will run more slowly.

  8. #8
    PowerPoster Evil_Giraffe's Avatar
    Join Date
    Aug 2002
    Location
    Suffolk, UK
    Posts
    2,555

    Re: My Graphics appear upside down?

    Quote Originally Posted by Shaggy Hiker View Post
    One thing you can do is translate all your points, but that would mean a calculation for each point (albeit a very simple one). Easier would be to just recognize that the origin is the upper left corner and live with it.
    It depends what your initial data is. If you've got points coming in from some source that has its own idea of what coordinates mean then it makes absolute sense to do the conversion for each point, and have the concept of world coordinates and view coordinates. This would include where the source concept is still a 2D plane with the origin at top left, because you still might need to pan and zoom around meaning that any point in the source doesn't necessarily map to that same point in the view.

    If you are dealing directly with drawing things to screen in a certain position in the window, yes, just recognise that is where the origin is and live with it.

  9. #9

    Thread Starter
    Addicted Member
    Join Date
    Jan 2013
    Posts
    177

    Re: My Graphics appear upside down?

    Thanks guys.

    Quote Originally Posted by dbasnett View Post

    I was looking at the graphics class, it didnt occur to me to look in the image class :P

    Quote Originally Posted by si_the_geek View Post
    To just flip the Y position, it's as simple as doing this for each point:
    Code:
    NewY = DisplayAreaHeight - OriginalY
    While using methods like RotateFlip may be slightly easier (assuming you pick the right parameters first time), they will run more slowly.
    This worked as well, will play around with both!

Posting Permissions

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



Featured


Click Here to Expand Forum to Full Width