f8 getLength()
{
return sqrt(X*X+Y*Y);
}
f8 getLengthSq()
{
return X*X+Y*Y;
}
f8 getDistance(const vector2d<T>& i_vec)
{
T tx=X-i_vec.X;
T ty=Y-i_vec.Y;
return sqrt(tx*tx+ty*ty);
}
T getDistanceSq(const vector2d<T>& i_vec)
{
T tx=X-i_vec.X;
T ty=Y-i_vec.Y;
return tx*tx+ty*ty;
}
vector2d<T>& normalize()
{
f8 a=X*X+Y*Y;
if(a==0.0||a==1.0) return *this;
a=sqrt(a);
X/=a;
Y/=a;
return *this;
}
vector2d<T>& rotateRad(f8 i_rad,const vector2d<T>& i_center=vector2d<T>(0,0))
{
T s=(T)sin(i_rad);
T c=(T)cos(i_rad);
X-=i_center.X;
Y-=i_center.Y;
T t1=X;
T ty=Y;
X=tx*c-ty*s;
Y=tx*s+ty*c;
X+=i_center.X;
Y+=i_center.Y;
return *this;
}
vector2d<T>& rotateDeg(f8 i_deg,const vector2d<T>& i_center=vector2d<T>(0,0))
{
i_deg=degToRad(i_deg);
T s=(T)sin(i_rad);
T c=(T)cos(i_rad);
X-=i_center.X;
Y-=i_center.Y;
T t1=X;
T ty=Y;
X=tx*c-ty*s;
Y=tx*s+ty*c;
X+=i_center.X;
Y+=i_center.Y;
return *this;
}
最終更新:2008年09月01日 15:54