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
TestDraw-0.0.1.tar.gz
Description: GNU Zip compressed data
------------------------------------------------------------------------------ SF.Net email is Sponsored by MIX09, March 18-20, 2009 in Las Vegas, Nevada. The future of the web can't happen without you. Join us at MIX09 to help pave the way to the Next Web now. Learn more and register at http://ad.doubleclick.net/clk;208669438;13503038;i?http://2009.visitmix.com/
_______________________________________________ Gambas-user mailing list Gambas-user@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/gambas-user