Author Topic: Map Projections (of the Earth): Any Experts?  (Read 2367 times)

0 Members and 1 Guest are viewing this topic.

Offline Qwerkey

  • Forum Resident
  • Posts: 755
Map Projections (of the Earth): Any Experts?
« on: January 02, 2022, 01:39:05 pm »
I am thinking of starting a project to display a revolving 3D transparent Earth globe.  To do this, I'll input a 2D map of the Earth and map that onto a sphere with _MAPTRIANGLE(3D) - I still am completely ignorant of _GL methods.

My starting problem is that I don't know which the many map projections to use to give the global Earth image the correct topology.

Would you be able to suggest what would be the most apposite project for this perceived method?  I'll probably start with Mercator if there is no guidance.

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
Re: Map Projections (of the Earth): Any Experts?
« Reply #1 on: January 02, 2022, 01:47:59 pm »
Happy New Year @Qwerkey,

I could fairly easily do this without GL.
1. I have code to outline the Earth's land masses on rectangular sheet
2. I have code to project a rectangular sheet onto a spinning sphere
1 + 2 = mission accomplished

In fact I had Santa & Co. silhouette orbiting the Earth one Christmas.

These are here in forum but awhile ago.

Do you need this for something else or should we leave this as exercise challenge for yourself? Or do you want this through GL (I hope Wiki GL keywords back up now?)

Offline Qwerkey

  • Forum Resident
  • Posts: 755
Re: Map Projections (of the Earth): Any Experts?
« Reply #2 on: January 02, 2022, 01:54:34 pm »
Hi, @bplus Happy New Year

I'll look up your existing project (this was going to be a challenging exercise for me), but if you've covered it more-or-less I should not want to duplicate.

Richard

Offline MasterGy

  • Seasoned Forum Regular
  • Posts: 327
  • people lie, math never lies
Re: Map Projections (of the Earth): Any Experts?
« Reply #3 on: January 02, 2022, 02:10:04 pm »
Hello ! I don’t want to take your mind off the creation, but I’ve done this before. For games, I use this to draw the sky. Essentially, the game is inside a sphere, so the sky is realistic.

* earth.zip (Filesize: 9.88 MB, Downloads: 95)

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
Re: Map Projections (of the Earth): Any Experts?
« Reply #4 on: January 02, 2022, 09:34:20 pm »
Well what I thought wouldn't take much time, did. Troubles with editing the image so I could use one transparent color then troubles getting the backside working with the front side, whew! But I did it!

 
Sphere Sim Transparent Earth.PNG




* Sphere Sim Transparent Earth.zip (Filesize: 759.92 KB, Downloads: 64)

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
Re: Map Projections (of the Earth): Any Experts?
« Reply #5 on: January 02, 2022, 09:58:08 pm »
No sooner than I post than I get an idea for Mod!

 
Transparent Earth 2.PNG


Same images as in zip above, just a mod of the source code here:
Code: QB64: [Select]
  1. _Title "Fake sphere mapping Mod 4 trans world 2" 'b+ 2022-01-02
  2.  
  3. Dim As Long surface, gw, gh, map, y, x
  4. Dim clr~&
  5. Screen _NewImage(800, 600, 32)
  6. _ScreenMove 200, 100
  7. surface& = _LoadImage("map.png") ' 700 x 391
  8.  
  9. ' new 2022-01-01 part =========================================================================
  10. ' need to find the actual top, left and bottom right points inside map
  11. 'Do
  12. '    Cls
  13. '    _PutImage (0, 0), surface&, 0
  14. '    While _MouseInput: Wend
  15. '    Print _MouseX, _MouseY
  16. '    _Display
  17. '    _Limit 100
  18. 'Loop
  19. ' 48 to 688 = 640 pixels  found by pointing at spots I wanted
  20. ' 37 to 356 = 320 pixels
  21.  
  22. gw = 639
  23. gh = 320
  24. map& = _NewImage(gw, gh, 32)
  25. '_Dest map&
  26. _PutImage (0, 0)-(638, 319), surface&, map&, (48, 37)-Step(gw, gh) ' get the world section without labeling and such
  27. _PutImage (0, 0), map&, 0 ' OK one pixel off from (48, 36)
  28. For y = 0 To 319
  29.     For x = 0 To 638
  30.         If y = 0 Or y = 319 Then
  31.             PSet (x, y), &HFF000000
  32.         Else
  33.             clr~& = Point(x, y)
  34.             If IsNear&(clr~&, &HFFFFFFFF, 80) Then
  35.                 PSet (x, y), &HFF000000
  36.             Else
  37.                 PSet (x, y), &HFFFFFFFF
  38.             End If
  39.         End If
  40.     Next
  41. _PutImage (0, 0), 0, map, (0, 0)-(638, 319) ' screen to map
  42. _PutImage (0, 0), map&, 0 ' map to screen
  43. _ClearColor _RGB32(0, 0, 0), map&
  44. 'Color , &HFFFFFF00    'checking
  45. 'Cls
  46. '_PutImage (0, 0), map&, 0 ' there is someting off white around the black lines
  47. 'Sleep ' OK  got the image
  48.  
  49. ' ==================================================================================
  50. Dim stars As Long
  51.  
  52. stars& = _LoadImage("stars.png")
  53. _Source stars&
  54.  
  55. Dim As Double r, xc, yc, xo, x1, tv, tu, xo2, rr
  56. Dim pc~&
  57. Dim As Long rd, gr, bl, al
  58. r = _Height / 3
  59. xc = _Width / 2
  60. yc = _Height / 2
  61. xo = 0: xo2 = .5 * gw
  62. _Source map&
  63.     Cls
  64.     _PutImage , stars&, 0
  65.     ' new ============================= the backside!
  66.     For y = -r To r
  67.         x1 = Sqr(r * r - y * y)
  68.         tv = (_Asin(y / r) + 1.5) / 3
  69.         For x = -x1 + 1 To x1 - 1
  70.             tu = (_Asin(-x / x1) + 1.5) / 6
  71.             pc~& = Point((xo2 + tu * gw) Mod gw, tv * gh)
  72.             cAnalysis pc~&, rd, gr, bl, al
  73.             PSet (x + xc, y + yc), _RGB32(rd - 50, gr - 50, bl, al)
  74.         Next
  75.     Next y
  76.     xo2 = (xo2 + 1) Mod gw
  77.     fcirc xc, yc, r, _RGB32(255, 255, 255, 30)
  78.     ' fill with some haze
  79.     For rr = r To 0 Step -10
  80.         fcirc xc, yc, rr, _RGB32(30, 10, 30, 40)
  81.     Next
  82.     '=======================================================================
  83.  
  84.     For y = -r To r
  85.         x1 = Sqr(r * r - y * y)
  86.         tv = (_Asin(y / r) + 1.5) / 3
  87.         For x = -x1 + 1 To x1 - 1
  88.             tu = (_Asin(x / x1) + 1.5) / 6
  89.             pc~& = Point((xo + tu * gw) Mod gw, tv * gh)
  90.             PSet (x + xc, y + yc), pc~&
  91.         Next
  92.     Next
  93.     xo = (xo + 1) Mod gw
  94.     _Display
  95.  
  96.  
  97. Sub cAnalysis (c As _Unsigned Long, outRed As Long, outGrn As Long, outBlu As Long, outAlp As Long)
  98.     outRed = _Red32(c): outGrn = _Green32(c): outBlu = _Blue32(c): outAlp = _Alpha32(c)
  99.     'Print "cAnalysis says:"; outRed; outGrn; outBlu; outAlp
  100.  
  101. 'this function needs: cAnalysis (c As _Unsigned Long, outRed as long, outGrn as long, outBlu as long, outAlp as long)
  102. Function IsNear& (colr As _Unsigned Long, nearColr As _Unsigned Long, nearness As Long)
  103.     'try color +-5 on RGB as near
  104.     Dim As Long cRed, cGrn, cBlu, dummy, nRed, nGrn, nBlu
  105.     cAnalysis colr, cRed, cGrn, cBlu, dummy
  106.     'Print cRed, cGrn, cBlu
  107.     cAnalysis nearColr, nRed, nGrn, nBlu, dummy
  108.     'Print nRed, nGrn, nBlu
  109.     If Abs(cRed - nRed) <= nearness Then
  110.         If Abs(cGrn - nGrn) <= nearness Then
  111.             If Abs(cBlu - nBlu) <= nearness Then IsNear& = -1
  112.         End If
  113.     End If
  114.  
  115. Sub fcirc (CX As Long, CY As Long, R As Long, C As _Unsigned Long)
  116.     Dim Radius As Long, RadiusError As Long
  117.     Dim X As Long, Y As Long
  118.     Radius = Abs(R): RadiusError = -Radius: X = Radius: Y = 0
  119.     If Radius = 0 Then PSet (CX, CY), C: Exit Sub
  120.     Line (CX - X, CY)-(CX + X, CY), C, BF
  121.     While X > Y
  122.         RadiusError = RadiusError + Y * 2 + 1
  123.         If RadiusError >= 0 Then
  124.             If X <> Y + 1 Then
  125.                 Line (CX - Y, CY - X)-(CX + Y, CY - X), C, BF
  126.                 Line (CX - Y, CY + X)-(CX + Y, CY + X), C, BF
  127.             End If
  128.             X = X - 1
  129.             RadiusError = RadiusError - X * 2
  130.         End If
  131.         Y = Y + 1
  132.         Line (CX - X, CY - Y)-(CX + X, CY - Y), C, BF
  133.         Line (CX - X, CY + Y)-(CX + X, CY + Y), C, BF
  134.     Wend
  135.  
  136.  
« Last Edit: January 02, 2022, 10:07:31 pm by bplus »

Offline johnno56

  • Forum Resident
  • Posts: 1270
  • Live long and prosper.
Re: Map Projections (of the Earth): Any Experts?
« Reply #6 on: January 03, 2022, 08:28:37 am »
I'm liking the background... nudge, nudge, wink, wink... lol

Cool planet!
Logic is the beginning of wisdom.

Offline DANILIN

  • Forum Regular
  • Posts: 128
    • Danilin youtube
Re: Map Projections (of the Earth): Any Experts?
« Reply #7 on: January 03, 2022, 10:27:14 am »
Earth is spinning counterclockwise

Sun is first in Russia
and further Atlantic and further Alaska
Russia looks world from future. big data is peace data.
https://youtube.com/playlist?list=PLBBTP9oVY7IagpH0g9FNUQ8JqmHwxDDDB
i never recommend anything to anyone and always write only about myself

Offline Qwerkey

  • Forum Resident
  • Posts: 755
Re: Map Projections (of the Earth): Any Experts?
« Reply #8 on: January 03, 2022, 10:38:03 am »
@DANILIN is quite correct.  @bplus has the World spinning in the wrong direction.

And another thing!  This was going to be my little (entertaining) project, but @bplus & @MasterGy have got there before me.  These guys don't leave any crumbs for us lower coding mortals!

However, I see that the UK doesn't appear in @bplus 's World (we're just insignificant, I know!  Along with Ireland, Iceland and other insignificant places!).  If I start my own project (where I'd had the thought of doing some _MEM manipulations as well), I might let the user choose the position of the viewing centre.  Does QB64 do "Location sensing"?

An altogether lesser mortal.
« Last Edit: January 03, 2022, 10:50:38 am by Qwerkey »

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
Re: Map Projections (of the Earth): Any Experts?
« Reply #9 on: January 03, 2022, 11:50:34 am »
@DANILIN is quite correct.  @bplus has the World spinning in the wrong direction.

And another thing!  This was going to be my little (entertaining) project, but @bplus & @MasterGy have got there before me.  These guys don't leave any crumbs for us lower coding mortals!

However, I see that the UK doesn't appear in @bplus 's World (we're just insignificant, I know!  Along with Ireland, Iceland and other insignificant places!).  If I start my own project (where I'd had the thought of doing some _MEM manipulations as well), I might let the user choose the position of the viewing centre.  Does QB64 do "Location sensing"?

An altogether lesser mortal.

Right, dang! spinning is wrong and too many missing details, gots to have Ireland or I wouldn't exist :)

Maybe I'll borrow one of @MasterGy maps whose nice job also seems to have world going wrong way too plus I wouldn't mind if globe went in same direction as mouse, great focus in and out with mouse clicks!

Anyway for the technique we are using, Mercator Projection distortions on flat map seem repaired by sphere code (to answer @Qwerkey original question).

@Qwerkey mortals learn from the gods, I got my algo from Paul Dunn who is as UKanian as you. Of course it helps to have code another can read and understand mostly.

« Last Edit: January 03, 2022, 11:58:14 am by bplus »

Offline Qwerkey

  • Forum Resident
  • Posts: 755
Re: Map Projections (of the Earth): Any Experts?
« Reply #10 on: January 03, 2022, 12:29:37 pm »
@bplus is correct in pointing out that we mere mortals are in the presence of powers gods at QB64.  Our chief god is Germanic/Norse, Odin (or Woden in Anglo-Saxon).  He has his Special Day of the Week, of course, so perhaps we might rename this site the Wednesday Club?!

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
Re: Map Projections (of the Earth): Any Experts?
« Reply #11 on: January 03, 2022, 01:32:07 pm »
OK I fixed the whole world!

Got it spinning in correct direction and used MasterGy's outline-world-map.jpg which was allot easier to work with and provided much more detail.

Most all those islands are back!
 
Fixed transparent world country outlines.PNG


Zip contains all you need to run and see spinning, which just needed to reverse the 2 xo ( x offset or pointer of x on map).

* Sphere Sim Transparent Earth fixed.zip (Filesize: 1.27 MB, Downloads: 69)

Offline MasterGy

  • Seasoned Forum Regular
  • Posts: 327
  • people lie, math never lies
Re: Map Projections (of the Earth): Any Experts?
« Reply #12 on: January 03, 2022, 06:02:16 pm »
I think it was very good

Offline SierraKen

  • Forum Resident
  • Posts: 1454
Re: Map Projections (of the Earth): Any Experts?
« Reply #13 on: February 26, 2022, 05:42:04 pm »
This is INCREDIBLE B+!!! I searched for "Earth globe" and found this today. I've never seen such a good rotated Earth on my computer before. GOOD JOB!

Offline Pete

  • Forum Resident
  • Posts: 2361
  • Cuz I sez so, varmint!
Re: Map Projections (of the Earth): Any Experts?
« Reply #14 on: February 26, 2022, 07:58:30 pm »
Un-B-Plusing-lievable!

What is the outline-world-map.jpg used for? I see it has the country borders, but when I downloaded the "fixed" version and ran it, I still got the borderless countries display. I tried swapping out map.png with outline-world-map.jpg but no bueno.

Pete
Want to learn how to write code on cave walls? https://www.tapatalk.com/groups/qbasic/qbasic-f1/