[Bf-python] (no subject)

Gilbert, Joseph jgilbert at tigr.org
Sun Feb 20 20:23:28 CET 2005


Actually it's a good question.  I just ran a test on mathutils. Prob is that anglebetweenvecs() uses a internal blender function called saacos() found in arthrib.c.  (where most of mathutils gets it's math from) 

float saacos(float fac)
{
	if(fac<= -1.0f) return (float)M_PI;
	else if(fac>=1.0f) return 0.0;
	else return (float)acos(fac);
}

This function basically calculates the arc-cosine of a number and also tests to see if the number is between -1 and 1 (I believe this is because it expects normalized values). It then does acos() using a float and returning a float.  This gives (on my system at least) only 8-digit precision. So when anglebetweenvecs() calls:

return PyFloat_FromDouble( ( double )
				   ( angleRads * ( 180 / Py_PI ) ) );

angleRads is only precise out to 8 digits. 
I did an experiment and changed things to double and I was getting 16-digit precision. I return a result of 90.0000000000

Double precision:

	norm	1.4142135	float
	x	2	int
	dot	0.00000000000000000	double
	angleRads	1.5707963267948966	double
	angleRads * (180 / 3.14159265358979323)	90.000000000000000	double
	vec1->size	2	int
	vec2->size	2	int
	vec1->vec[0]	0.70710677	float
	vec1->vec[1]	0.70710677	float
	vec2->vec[0]	0.70710677	float
	vec2->vec[1]	-0.70710677	float

Float precision:

	norm	1.4142135	float
	x	2	int
	dot	-1.2688051e-008	float
	angleRads	1.5707964	float
	angleRads * (180 / 3.14159265358979323)	90.000002504478161	double
	vec1->size	2	int
	vec2->size	2	int
	vec1->vec[0]	0.70710677	float
	vec1->vec[1]	0.70710677	float
	vec2->vec[0]	0.70710677	float
	vec2->vec[1]	-0.70710677	float


I'll see If I can update places where float precision is hindering output results. Doh :)

-----Original Message-----
From: bf-python-bounces at projects.blender.org [mailto:bf-python-bounces at projects.blender.org] On Behalf Of Gabriel Beloin
Sent: Sunday, February 20, 2005 1:18 PM
To: Blender Foundation Python list
Subject: [Bf-python] (no subject)

try this code in blender:
----------------------------------
import Blender
from Blender import Mathutils

a = Mathutils.Vector(1,1)
b = Mathutils.Vector(1,-1)

print Mathutils.AngleBetweenVecs(a,b)
----------------------------------
The result is 90.0000025045.
Why on earth a square angle between 2 vectors could equal 90.0000025045. Or its me that is missing something?

C est le moment de dynamiser votre boîte mail en découvrant les offres CaraMail Max et Pro - http://www.caramail.com




More information about the Bf-python mailing list