[Gambas-user] Coordinate system in Gambas Graphics

Doriano Blengino doriano.blengino at ...1909...
Mon Dec 15 23:22:37 CET 2008


Jesus Guardon ha scritto:
> Hi Doriano and list
>
> First of all, many thanks for your input. 
>
> Yes, you are right about geographic coordinates; in real world the
> intersection between Ecuatorial line and Greenwich meridian is the
> coordinate 0;0.  Meridians above increase up to 90 degrees to North and
> below to -90 South. By the way, parallels increase up to 180 deg to East and
> -180 to West from Greenwich (parallel 0). So the upper left corner (in case
> of a whole World map) should be -180;90 and the lower right corner 180;-90.
> Based on this, the result rectangle will be 360 units wide * 180 units tall. 
>   
Are you sure meridians go from -90 to 90? Ore are they parallels?
I ask this because I live near the 45° parallel: a sign in the motorway 
states "Half way from Ecuator to Pole".
I think Parallels are, just as they name says, "parallel" to the 
ecuator; Meridians are those that define the time (Greenwich, +1, -1, 
and so on...)
So, correct me if I am wrong, Parallels go from south to north, and 
Meridians from east to west (or vice-versa).

> But still is unclear if I can use negative values mapped to a rectangle, as
> you appointed in your previous post. The idea is to have a procedure that
> can do e.g.  drawCoordinate(-3, 40), and draws a point (or whatever I want)
> on the correct place.
>   
As far as I understand, you *can* use negative world coordinates; they 
will be happily translated to physical (device) coordinates. If the 
result of this transformation lies in the range 0..Max (0 to 799 for 
horizontal, and 0 to 599 for vertical) then they will be visible, 
otherwise they will be clipped.

The problem is that your world coordinates, as one could expect, are 
oriented in the "up" direction: south is negative and north is positive.
To map the world (360 x 180) on your 800 x 400 picture you do this:

  Draw.scale(800/360, 400/180)

I chose a picture of 800x400 pixels so the scaling in the 2 axis is the 
same, but I could be wrong (because meridians are not parallel, right?).
Then, we have to move the origin, because the zero of both horizontal 
and vertical axes must go to the center of the picture:

  Draw.translate(180, 90)

With this setup, if you plot a real world point at 0N, 0W, the 
coordinates inside the picture will be:

  X = (0 + 180) * 800/360      -> 400   (the center of the image)
  Y = (0 + 90) * 400/180         -> 200   (the mid of the image)

If you plot a 36, 45 (more or less where I live):

  X = (36 + 180) * 800/360   -> a little step to the right of the center 
of the image
  Y = (45 + 90) * 400/180      -> 300, well below the ecuator... WRONG! 
I don't live in Africa...

As I stated before, we should have a negative Y scaling; Benoit could 
confirm or not: does a negative scaling work?

Well, we simply have to reverse the Y axis; instead of using the 
North-South coordinate as is, we must use (90-coordinate) and move the
origin this way:

    draw.translate(180, 0)

Doing so, the coordinate where I live (the 45° Parallel), should become:

  Y = ((90-45) + 0) * 400/180      -> 100, near the top of the image

The North Pole:

  Y = ((90-90) + 0) * 400/180      -> 0, at the top of the image

and the South Pole:

  Y = ((90- -90) + 0) * 400/180   -> 180*400/180   -> 400, the bottom of 
the image

...perhaps I made a mess - it's not clear to me how this geographic 
coordinates work but, at least for me, it has been funny... :-)

Regards,
Doriano


> Let me play for a while with your program, write some garbage on my notebook
> and I will post here my results. Again, thank you for your interest.
>
> Jesus Guardon
>
> Gambas 2.9 
>
>
> Doriano Blengino wrote:
>   
>> 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
>>
>>
>>
>>  
>> ------------------------------------------------------------------------------
>> 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 at lists.sourceforge.net
>> https://lists.sourceforge.net/lists/listinfo/gambas-user
>>
>>
>>     
>
>   


-- 
Doriano Blengino

"Listen twice before you speak.
This is why we have two ears, but only one mouth."





More information about the User mailing list