Skip to content
Snippets Groups Projects
Commit 2826b5bc authored by Andreas Schenk's avatar Andreas Schenk
Browse files

fixed bug in SignedAngle for parallel Vec2s / added export for SingedAngle

parent f9ff5e87
Branches
Tags
No related merge requests found
......@@ -33,6 +33,7 @@ Real (*Mat2Det)(const Mat2& m) = &Det;
Mat2 (*Mat2Invert)(const Mat2& m) = &Invert;
Mat2 (*Mat2Transpose)(const Mat2& m) = &Transpose;
Real (*Vec2Angle)(const Vec2& v1, const Vec2& v2) = &Angle;
Real (*Vec2SignedAngle)(const Vec2& v1, const Vec2& v2) = &SignedAngle;
Vec2 (*Vec2Normalize)(const Vec2& v1) = &Normalize;
Vec2 (*Vec2Rotate)(const Vec2& v1,Real ang) = &Rotate;
Vec2 (*Vec2Min)(const Vec2&, const Vec2&) = &Min;
......@@ -53,6 +54,7 @@ void export_VecMat2_op()
def("Invert",Mat2Invert);
def("Transpose",Mat2Transpose);
def("Angle",Vec2Angle);
def("SignedAngle",Vec2SignedAngle);
def("Normalize",Vec2Normalize);
def("Rotate",Vec2Rotate);
def("Min",Vec2Min);
......
......@@ -55,11 +55,15 @@ Real Angle(const Vec2& v1, const Vec2& v2)
Real SignedAngle(const Vec2& v1, const Vec2& v2)
{
Vec3 vc;
vc=Cross(Vec3(v1),Vec3(v2));
if(Length(v1)==0.0 || Length(v2)==0.0 || Length(vc)==0.0)
if(Length(v1)==0.0 || Length(v2)==0.0){
return 0.0;
return acos(Dot(v1,v2)/Length(v1)/Length(v2))*vc.z/std::fabs(vc.z);
}
Vec3 vc=Cross(Vec3(v1),Vec3(v2));
Real sign=1.0;
if(vc.z!=0.0){
sign=vc.z/std::fabs(vc.z);
}
return acos(Dot(v1,v2)/Length(v1)/Length(v2))*sign;
}
Vec2 Rotate(const Vec2& v,Real ang)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment