Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations sizbut on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Help needed with maths function and calculation urgent!

Status
Not open for further replies.

hbutt

Programmer
Apr 15, 2003
35
GB
hi there i just wanted to know if there was a way doing the following mathematical equation more easily.

static float distanceToBuilding(TravellerSprite travellersprite, BuildingSprite buildingsprite)
{
float f = (float)buildingsprite.xcoord - travellersprite.xcoord;
float f1 = (float)buildingsprite.ycoord - travellersprite.ycoord;
return (float)Math.sqrt(f * f + f1 * f1);
}
thanx. hbutt
 
yours is the generic problem of finding the distance between two points of a rectangular co-ordinate system when the co-ordinates of both the points are known.
your code exactly reflects the standard formula and IMHO cannot be bettered.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top