Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Vector bearing returns integer #141

Open
luppiale opened this issue Jul 22, 2020 · 0 comments
Open

Vector bearing returns integer #141

luppiale opened this issue Jul 22, 2020 · 0 comments

Comments

@luppiale
Copy link

The 2 methods of Vector class returns integer instead of float value.

public function initialBearing()
    {
        Ellipsoid::checkCoordinatesEllipsoid($this->from, $this->to);

        $latA = deg2rad($this->from->getLatitude());
        $latB = deg2rad($this->to->getLatitude());
        $dLng = deg2rad($this->to->getLongitude() - $this->from->getLongitude());

        $y = sin($dLng) * cos($latB);
        $x = cos($latA) * sin($latB) - sin($latA) * cos($latB) * cos($dLng);

        return (float) (rad2deg(atan2($y, $x)) + 360) % 360;
    }

Using % with float variables cast it to integer losing a lot of precision.
If u want an angle between 0 and 360 you can do something like this

$angle = rad2deg(atan2($y, $x)) + 360;
return $angle > 360 ? $angle - 360 : $angle;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant