-
Apr 25th, 2013, 03:20 PM
#1
Thread Starter
Addicted Member
[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
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.
-
Apr 25th, 2013, 03:38 PM
#2
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:
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'!
-
Apr 25th, 2013, 04:32 PM
#3
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
-
Apr 25th, 2013, 06:43 PM
#4
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!
-
Apr 26th, 2013, 07:45 AM
#5
Thread Starter
Addicted Member
Re: My Graphics appear upside down?
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:
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
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.
-
Apr 26th, 2013, 07:50 AM
#6
Re: My Graphics appear upside down?
-
Apr 26th, 2013, 08:00 AM
#7
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.
-
Apr 26th, 2013, 08:39 AM
#8
Re: My Graphics appear upside down?
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.
-
Apr 26th, 2013, 09:10 AM
#9
Thread Starter
Addicted Member
Re: My Graphics appear upside down?
Thanks guys.
Originally Posted by dbasnett
I was looking at the graphics class, it didnt occur to me to look in the image class :P
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!
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|