Jump to content

getAngle function


photo

Recommended Posts

Hi Dongju,

As written in the docs,  the getAngle(v0,v1) function returns an unsigned acute angle between the two vectors (the smaller of the two possible angles). The result is within the [0.0; 180.0] range.

While the getAngle(v0, v1, up) function returns a signed angle relative to the up vector specified. The result is within the [-180.0; 180.0] range.

float getAngle(const vec3 &v0, const vec3 &v1)
{
	float d = dot(v0, v1) / (length(v0) * length(v1));
	return acos(clamp(d, -1.0f, 1.0f)) * RAD2DEG;
}

float getAngle(const vec3 &v0, const vec3 &v1, const vec3 &up)
{
	vec3 n = cross(v0, v1);
	return atan2(dot(normalize(up), n), dot(v0, v1)) * RAD2DEG;
}

Thank you!

Link to comment
  • 4 weeks later...

I want value of range about quat->getangle() not Math's getAngle().

quat->getAngle() range is 0~180 too???

 

I checked with Log, it looks like -180~180. 
Thank you for your answers.

Edited by dongju.jeong
Link to comment
×
×
  • Create New...