Navigacija
Lista poslednjih: 16, 32, 64, 128 poruka.

Izlazak i zalazak sunca, sunrise sunset calculation

[es] :: Javascript i AJAX :: Izlazak i zalazak sunca, sunrise sunset calculation

[ Pregleda: 2532 | Odgovora: 1 ] > FB > Twit

Postavi temu Odgovori

Autor

Pretraga teme: Traži
Markiranje Štampanje RSS

MilosDj
Milos Djuric
Belgrade

Član broj: 14174
Poruke: 307
*.dynamic.isp.telekom.rs.



+4 Profil

icon Izlazak i zalazak sunca, sunrise sunset calculation30.11.2011. u 23:24 - pre 150 meseci
Da li neko ima gotovu funkciju koja racuna izlazak i zalazak sunca za zadati datum?

Nasao sam ovaj postupak ali krajnji rezultat je pogresan. Imam dve varijante moje funkcije. Jedna u stepenima druga u radijanima, al obe ne rade.
Evo koda za stepene ako neko zeli da pogleda:
Code:
// prva verzija koja ne radi
sunrise_time = function (lat, lon, time, zen) {


    var day_of_year, lon_hour,    trise, tset,    // longitude in hours
    Mrise, Mset,    // sun mean anomaly
    Lrise, Lset,    // sun true longitude
    RArise, RAset,    // suns right ascention
    Lquadrant, RAquadrant,    // need to be in same quadrant
    sinDecrise,sinDecset, cosDecrise,cosDecset,    // suns declination
    cosHrise, cosHset,    // sun local hour angle
    Hrise, Hset,    // in hours
    Trise, Tset,    // local mean time of rise and set
    UTrise, UTset,    // universal time
    sunrise, sunset, day_length;

    lat = lat || 44.49; // Latitude:     44° 49'     North. Belgdare
    lon = lon || 20.28; // Longitude:     20° 28'     East 

    if (typeof zen === 'string')
    {
        //zen = zen.charAt(0);    // first letter
    switch (zen)
    {
        case 'o':
        case 'offical':
        case 'official':
            zen = 90.5;
        break;
    
        case 'n':
        case 'nautical':
            zen = 102;
        break;
    
        case 'a':
        case 'astro':
        case 'astronomical':
            zen = 108;
        break;
        
        case 'c':
        case 'civil':
        default:
            zen = 96;
    }
    }
    else if (isFinite(zen))
    {
        //zen = zen;
    }
    else
    {
        zen = 96;    // civil
    }

// 1.
    day_of_year = f.day_of_year(time);    // N
//    console.log(day_of_year +' lat: ' + lat +' lon: ' + lon +' time: ' + time +' zenit: ' +  zen);
    
    
// 2.
// convert the longitude to hour value and calculate an approximate time
    lon_hour = lon / 15;
    
    trise = day_of_year + (6 - lon_hour) / 24;    // t
    tset = day_of_year + (18 - lon_hour) / 24;    // t
//console.log(trise +' ' + tset);
    
// 3. calculate the Sun's mean anomaly
    Mrise = (0.9856 * trise) - 3.289;    // M
    Mset = (0.9856 * tset) - 3.289;    // M    // rad???
//    console.log(Mrise + ' ' + Mset);

// 4. calculate the Sun's true longitude
    
    Lrise = Mrise + (1.916 * 180/Math.PI * Math.sin(Math.PI/180 * Mrise)) + (0.020 * 180/Math.PI * Math.sin(Math.PI/180 * 2 * Mrise)) + 282.634;
    Lset = Mset + (1.916 * 180/Math.PI * Math.sin(Math.PI/180 * Mset)) + (0.020 * 180/Math.PI * Math.sin(Math.PI/180 * 2 * Mset)) + 282.634;

//    L potentially needs to be adjusted into the range [0,360) by adding/subtracting 360
    if (Lrise >= 360) { Lrise -= 360; }    // Lrise -= 2*Math.PI;
    if (Lset >= 360) { Lset -= 360; }
    
    
// 5a. calculate the Sun's right ascension
    
    RArise = 180/Math.PI * Math.atan(0.91764 * Math.tan(Math.PI/180 * Lrise));
    RAset = 180/Math.PI * Math.atan(0.91764 * Math.tan(Math.PI/180 * Lset));

//    RA potentially needs to be adjusted into the range [0,360) by adding/subtracting 360
    if (RArise >= 360) {RArise -= 360;}
    if (RAset >= 360) {RAset -= 360;}

// 5b. right ascension value needs to be in the same quadrant as L
    Lquadrant  = Math.floor(Lrise/90) * 90;
    RAquadrant = Math.floor(RArise/90) * 90;
    RArise = RArise + (Lquadrant - RAquadrant);

    Lquadrant  = Math.floor(Lset/90) * 90;
    RAquadrant = Math.floor(RAset/90) * 90;
    RAset = RAset + (Lquadrant - RAquadrant);
    
// 5c. right ascension value needs to be converted into hours
    RArise = RArise / 15;
    RAset = RAset / 15;
    
    
// 6. calculate the Sun's declination
    sinDecrise = 0.39782 * Math.sin(Math.PI/180 * Lrise);
    cosDecrise = 180/Math.PI * Math.cos(Math.asin(sinDecrise));

    sinDecset = 0.39782 * Math.sin(Math.PI/180 * Lset);
    cosDecset = 180/Math.PI * Math.cos(Math.asin(Math.PI/180 * sinDecset));
    
// 7a. calculate the Sun's local hour angle
    cosHrise = (180/Math.PI * Math.cos(Math.PI/180 * zen) - (sinDecrise * 180/Math.PI * Math.sin(Math.PI/180 * lat))) / (cosDecrise * 180/Math.PI * Math.cos(Math.PI/180 * lat));
    cosHset = (180/Math.PI * Math.cos(Math.PI/180 * zen) - (sinDecset * 180/Math.PI * Math.sin(Math.PI/180 * lat))) / (cosDecset * 180/Math.PI * Math.cos(Math.PI/180 * lat));
    
    if (cosHrise >  1)
    {
        // the sun never rises on this location (on the specified date)
        sunrise = 'Sun never rises here on this day.';
    }
    if (cosHset < -1)
    {
        //the sun never sets on this location (on the specified date)
        sunset = 'Sun never sets here on this day.';
    }
    
    
// 7b. finish calculating H and convert into hours
    
    Hrise = 360 - 180/Math.PI * Math.acos(Math.PI/180 * cosHrise);
    
    Hset = 180/Math.PI * Math.acos(Math.PI/180 * cosHset);
    
    Hrise = Hrise / 15;
    Hset = Hset / 15;
    
    
// 8. calculate local mean time of rising/setting
    Trise = Hrise + RArise - (0.06571 * trise) - 6.622;
    Tset = Hset + RArise - (0.06571 * tset) - 6.622;
    

// 9. adjust back to UTC
    UTrise = Trise - lon_hour;
    UTset = Tset - lon_hour;
    
//    UT potentially needs to be adjusted into the range [0,24) by adding/subtracting 24
    if (UTrise >= 24) UTrise -=24;
    if (UTrise < 0) UTrise +=24;

    if (UTset >= 24) UTset -=24;
    if (UTset < 0) UTset +=24;

    

// 10. convert UT value to local time zone of latitude/longitude
    
    var localOffset = 1;
sunrise = UTrise ;
sunset = UTset ;
    
    
    
    
//return [UTrise, UTset];
    return [f.dec2hmin(sunrise), sunset, day_length];
};

I'm not in this world to live up to your expectations and you're not in this world to live up to mine.
 
Odgovor na temu

MilosDj
Milos Djuric
Belgrade

Član broj: 14174
Poruke: 307
*.dynamic.isp.telekom.rs.



+4 Profil

icon Re: Izlazak i zalazak sunca, sunrise sunset calculation23.01.2012. u 13:41 - pre 149 meseci
Nasao sam i neznatno debagovao sun_table funkciju. Vraca string tabelu sa civilnim, nautickim i astronomskim izlaskom i zalaskom sunca. Fino je sto izracunava izlazak i zalazak meseca.

Celo problmem upste nije naivan.
I'm not in this world to live up to your expectations and you're not in this world to live up to mine.
Prikačeni fajlovi
 
Odgovor na temu

[es] :: Javascript i AJAX :: Izlazak i zalazak sunca, sunrise sunset calculation

[ Pregleda: 2532 | Odgovora: 1 ] > FB > Twit

Postavi temu Odgovori

Navigacija
Lista poslednjih: 16, 32, 64, 128 poruka.