[Gambas-user] Coordinate system in Gambas Graphics
Doriano Blengino
doriano.blengino at ...1909...
Mon Dec 15 10:40:05 CET 2008
Jesus Guardon ha scritto:
>
> Doriano Blengino wrote:
>
>> simple linear transformation is possible by using draw.translate() and
>> draw.scale(); draw.reset() will reset the transformation matrix.
>> Draw.push() and draw.pop() exist to save and restore the matrix.
>>
>>
> Hi all
>
> Well, I'm totally lost with this subject. What I'm trying to do is to map
> the real world coordinates into a picture of a geographical map of Europe,
> for plotting parallels, meridians and some other stuff.
>
> Lets say we have a picture of Europe 800x600px and its real coordinates are:
> 72N -25W (upper left corner) and -18S 44E (bottom right corner). How do I
> translate pixels to coordinates to draw on the map directly using real
> coordinates?
> I don't understand very well what matrices are, and how to apply with Gambas
> syntax.
> Any example or explanation on how to accomplish this project are welcome.
>
> This is what I did so far in VB.net, but this is another history... :-)
> (in Spanish): http://ea7dfh.es/MapLoc/
>
I've set up a simple project to show how the transformation matrix works.
It draws a line from (0;0) to an arbitrary point you specify in LX: and LY:.
You can play with Draw.XXX fields to see they effect.
What I discovered is that (gambas vesion 2.0.0):
1) For me, negative scalings do not work; this is a *serious* limitation.
2) Offsets are multiplied by scaling, ie they are expressed in "real
world" coordinates.
3) Perhaps I am missing something, but it seems to me that you can not
read what is the current transformation matrix; the program should keep
track of this.
Now, I don't know what "72N" and "-25W" mean (I think north and west,
but that is all), anyway, supposing that they are arbitrary measurement
units, then your map is 44+25 units wide, and 72+18 units tall, ie 69 x 90.
You want map this to a 800 x 600. If you don't care about aspect ratio,
then do Draw.scale(800 / 69, 600 / 90).
If you want to mantain aspect ratio (it should be), you assign the same
value to scalex and scaley, the smaller of the two: 800/69=11.59,
600/90=6.66, so do Draw.scale(6.66, 6.66).
As your upper left corner is -25W and 72N, you must do
Draw.translate(25, -72).
At this point, plotting a (25; 72) should go to (0; 0) in the drawing area.
From here ahead, I think there is a problem with the computer graphics
having Y axis pointing to the bottom, so may be your map will be flipped
up side down. Every Y coordinate should be transformed by newy =
MapHeight-y, so a different draw.translate() must be issued.
Anyway, it seems to me that the combination of Scale() and Translate()
does the following:
coordinate_to_plot = (programmed_coordinate + translate_value) *
scale_value
Hope this is enough - I well could have done lot of errors, but the test
project can let you experiment.
Regards,
Doriano
-------------- next part --------------
A non-text attachment was scrubbed...
Name: TestDraw-0.0.1.tar.gz
Type: application/x-gzip
Size: 8134 bytes
Desc: not available
URL: <http://lists.gambas-basic.org/pipermail/user/attachments/20081215/14ac6c13/attachment.bin>
More information about the User
mailing list