• Quick note - the problem with Youtube videos not embedding on the forum appears to have been fixed, thanks to ZiprHead. If you do still see problems let me know.

Transforming coordinates

LandR

Graduate Poster
Joined
Sep 20, 2009
Messages
1,280
Hi,

I have a bit of a maths problem. I am drawing some triangles to screen with my program but my program draws to a paintbox (.net).

The left most coordinate of the paintbox is 0, the rightmost is 500. It's 500 pixels wide by 500 pixels high.

On this box I have drawn axis and a grid labelled from -1000 > 0 > 1000 for both X and Y axis.

The coordinates of the any vertex on the triangles range from (-1000,-1000) to (1000,1000).

I obviously can't draw them straight to the screen with these coordinates but my maths is so rusty. How can I transform the triangles co-ordinates so that:

-1000 = 0;
0 = 250
1000 = 500

??

I can write code to transform the coordinates I'm just not sure how I should go about it.

The initial problem was to find out of 1000 triangles how many contained the origin with their area. This I solved, it was simple enough. I decided though I would learn some graphics programming and allow you to draw the triangles to screen along with showing the calculations.

Sorry for being thick and Thank You if you help!
 
I usually do it like this: convert interval to 0..1 .. then it's simple.

So to get -1000 .. 1000 to 0..1 you do: (x+1000)/2000
To get the result to 0..500 you simply do ((x+1000)/2000)*500
 
Visual Basic had the SCALE (or WINDOW in QBasic) command, to define your own coordinate system. Isn't there something similar in whatever you are using?
 

Back
Top Bottom