From: nospam@needed.invalid   
      
   On Wed, 1/14/2026 8:28 AM, R.Wieser wrote:   
   > Ammammata,   
   >   
   >> i pasted your post into chatgpt, it says:   
   >>   
   >> You're very close - the issue is a combo of log base,   
   >   
   > Yeah, I noticed that too. log() != log() : loge(), log10(), ln(), lg().   
   >   
   >> formula form,   
   >   
   > You got me there I'm afraid. No idea what thats supposed to be about.   
   >   
   >> and how Mercator Y is mapped to pixels.   
   >   
   > Really ? I can't imagine.   
   >   
   >> Nothing fundamentally wrong   
   >> with your trig. Let's untangle it cleanly.   
   >>   
   >> then it explains a possible error in your formula and suggests   
   >> the workaround   
   >   
   > Can you post what it said about that explanation and work-around please.   
   >   
   > Regards,   
   > Rudy Wieser   
   >   
   >   
      
   ************ CoPilot Question *************   
      
   The mercator projection of the world globe can be displayed   
   on a computer screen. Assume the computer screen is a   
   unit square having a diagonal stretching from (0,0) to (1,1).   
   Write a C language program that accepts latitude and longitude in signed   
   degrees,   
   and computes the location of a dot on the screen in the unit square.   
      
   The interface to the program would say on the command line   
      
   Enter Latitude in degrees:   
      
   Enter Longitude in degrees:   
      
   Your screen data point is at X= Y=   
      
   The program then waits for the next data input without terminating.   
      
   ************ CoPilot Answer *************   
      
   #include    
   #include    
      
   /* gcc -lm -o merc.exe merc.c */   
      
   int main(void) {   
    double lat, lon;   
    const double PI = 3.14159265358979323846;   
      
    while (1) {   
    printf("\nEnter Latitude in degrees: ");   
    if (scanf("%lf", &lat) != 1) break;   
      
    printf("Enter Longitude in degrees: ");   
    if (scanf("%lf", &lon) != 1) break;   
      
    /* Clamp latitude to Mercator limits (~±85.05113°) */   
    if (lat > 85.05113) lat = 85.05113;   
    if (lat < -85.05113) lat = -85.05113;   
      
    /* Convert longitude to X in [0,1] */   
    double x = (lon + 180.0) / 360.0;   
      
    /* Convert latitude to Y in [0,1] using Mercator projection */   
    /* Paul: Lang C log() is actually ln(). While Lang C log10() is log   
   base10 */   
    double rad = lat * PI / 180.0;   
    double y = 0.5 - (log(tan(PI/4.0 + rad/2.0)) / (2.0 * PI));   
      
    printf("Your screen data point is at X=%f Y=%f\n", x, y);   
    }   
      
    return 0;   
   }   
   ************ End CoPilot Answer *************   
      
   It took a bit to convince myself that the equation shown   
   in the CoPilot answer was successfully converted to C code.   
      
   *******   
      
   New York : Latitude = 39 (Longitude = -77)   
      
   -- Applying the formula and checking the partial results :   
      
   RadLat = DegToRad(39) -> 0.680952380952381   
      
   Temp = tan(RadLat) + 1/cos(RadLat) -> 2.09728292053088   
      
   log(Temp)/log(10) -> 0.321657020135087   
      
   *******   
   The CoPilot program gives   
      
   Enter Latitude in degrees: 39   
   Enter Longitude in degrees: -77   
   Your screen data point is at X=0.286111 Y=0.382179   
      
   Now, we have to work on our "where is our damn plot origin". Surprise.   
   It's not where you think when they wrote the equation. Lets find out.   
      
   Enter Latitude in degrees: -80   
   Enter Longitude in degrees: 0   
   Your screen data point is at X=0.500000 Y=0.887741   
      
   Enter Latitude in degrees: -50   
   Enter Longitude in degrees: 0   
   Your screen data point is at X=0.500000 Y=0.660855   
      
   Enter Latitude in degrees: -30   
   Enter Longitude in degrees: 0   
   Your screen data point is at X=0.500000 Y=0.587425   
      
   Enter Latitude in degrees: 0   
   Enter Longitude in degrees: 0   
   Your screen data point is at X=0.500000 Y=0.500000   
      
   Enter Latitude in degrees: 30   
   Enter Longitude in degrees: 0   
   Your screen data point is at X=0.500000 Y=0.412575   
      
   Enter Latitude in degrees: 50   
   Enter Longitude in degrees: 0   
   Your screen data point is at X=0.500000 Y=0.339145   
      
   Enter Latitude in degrees: 80   
   Enter Longitude in degrees: 0   
   Your screen data point is at X=0.500000 Y=0.112259   
      
   (0,0) is on the upper left of the unit square.   
      
    Paul   
      
   --- SoupGate-Win32 v1.05   
    * Origin: you cannot sedate... all the things you hate (1:229/2)   
|