1 Attachment(s)
[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
Attachment 99451
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?
1 Attachment(s)
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:
Attachment 99455
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.
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.
Re: My Graphics appear upside down?
Quote:
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!
Re: My Graphics appear upside down?
Quote:
Originally Posted by
dday9
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:
Attachment 99455
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
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.
Re: My Graphics appear upside down?
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.
Re: My Graphics appear upside down?
Quote:
Originally Posted by
Shaggy Hiker
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.
Re: My Graphics appear upside down?
Thanks guys.
Quote:
Originally Posted by
dbasnett
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
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!