2 mathematical / class object questions
1. I represent a matrix using a float for each element. I don't use arrays, as they are not very efficent for a matrix class. For example, row 2 and column 3 would be represented as m23. Is this smart, or what are some other ways to represent matricies besides arrays?
2. Due to the nature of floating point variables, the length of a unit vector may not necessarily be exactly one. This means the length check
length() == 1.0f
may be false. Would this:
(length > .9999f) && (length < 1.1f)
return true, such as if length was 1.0000034? Or how else should I check for a normalized vector?
Thanks :D !
Re: 2 mathematical / class object questions
#1.
Code:
union
{
struct
{
float m11,m12,m13,m21,m22,m23,m31,m32,m33;
};
float m[3][3];
};
#2.
You can round, but you can't round to the units place, else 0.5 =1. It is simpler to just write
Code:
bool eqflt(float a,float b,float tol)
{
if(fabs(tol)>fabs(a-b)) return true;
return false;
}
if(eqflt(mag(vector),1.0f,0.00001f)) printf("normalized");