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 SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

acos dividing by zero

Status
Not open for further replies.

ashstampede

Programmer
Aug 30, 2004
104
0
0
GB
I'm very lost in the fact that acos is returning ?-1.#IND000

What i am trying to calculate is a angle from two vectors.
now my
"float dot" is a negative number so my assumtion is "that must be why it is returing dived by zero".

Code:
//Get the Tanks current Location
	Vector2D Alien = Vector2D();
	Alien.x = m_tank->GetX();
	Alien.z = m_tank->GetZ();

	// Get the Heading of the Tanks turret to a new vector
	Vector2D Heading = Vector2D();
	Heading.x = cursor->GetX();
	Heading.z = cursor->GetZ();

	//location of the Targeted Tank is the Target variable

	//We need to calculate the angle to turn to be centred with 
	//the target.
	
	//What is the direction Vector of the target
	//first subtract the vector
	Vector2D TargetPos = subtractVector(Target,Alien);
	//the normalize it
	normal(TargetPos);
	
	float dot = dotProduct(TargetPos,Heading);
	//the angle of rotation needed
	float theta = acos(dot);
	//convert to degrees.
	ToDegrees(theta);

the functions normal dotProduct are from [link] [/url]

the subtractVector is a function the subtract each individuall point ie. vec1.x - vec2.x as i didnt know how to overload the - sign for my structure.

thanks in advance.
 
acos will only take values between -1.0 and 1.0. What sort of values are you passing to it? Print statements/couts will help in this case.
 
I have sorted it out, it was the normalized, i didnt normalize heading vector so the numbers were over -1 and 1 so sorted. thanks for the response
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top