You are here: Re: [PHP] Calculation error - PHP not following math hierarchi ??? « PHP « IT news, forums, messages
Re: [PHP] Calculation error - PHP not following math hierarchi ???

Posted by Robin Vickery on 08/03/05 18:38

On 8/3/05, Rene Brehmer <piv@metalbunny.net> wrote:
> I've run into a situation where PHP is way off when doing a relatively
> simple calculation of distance between two points in 2-dimensional space,
> where coordinates go from 1 to 300 in both X and Y directions. When passing
> 300, it goes back to 1, and vise-versa (it's for a game and is supposed to
> approximate the movement over a sphere).
>
> Using this function:
>
> function calc_distance($curX,$curY,$newX,$newY) {
> // calculate distance to new location
> $distX = abs($curX - $newX);
> $distY = abs($curY - $newY);
>
> if ($distX <= 150 && $distY <= 150) {
> $dist = sqrt($distX^2 + $distY^2);

I don't think you really want to do a bitwise xor there.

http://www.php.net/manual/en/language.operators.bitwise.php

Try pow() instead

http://www.php.net/manual/en/function.pow.php

-robin

 

Navigation:

[Reply to this message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация