mirror of
https://git.mirrors.martin98.com/https://github.com/prusa3d/PrusaSlicer.git
synced 2025-08-15 20:25:57 +08:00
fix ccw angle computation in Point.cpp
This commit is contained in:
parent
177a1fd54a
commit
ca259caf33
@ -131,9 +131,11 @@ double Point::ccw(const Line &line) const
|
|||||||
// i.e. this assumes a CCW rotation from p1 to p2 around this
|
// i.e. this assumes a CCW rotation from p1 to p2 around this
|
||||||
double Point::ccw_angle(const Point &p1, const Point &p2) const
|
double Point::ccw_angle(const Point &p1, const Point &p2) const
|
||||||
{
|
{
|
||||||
//FIXME this calculates an atan2 twice! Project one vector into the other!
|
const Point v1 = *this - p1;
|
||||||
double angle = atan2(p1.x() - (*this).x(), p1.y() - (*this).y())
|
const Point v2 = p2 - *this;
|
||||||
- atan2(p2.x() - (*this).x(), p2.y() - (*this).y());
|
int64_t dot = int64_t(v1(0)) * int64_t(v2(0)) + int64_t(v1(1)) * int64_t(v2(1));
|
||||||
|
int64_t cross = int64_t(v1(0)) * int64_t(v2(1)) - int64_t(v1(1)) * int64_t(v2(0));
|
||||||
|
float angle = float(atan2(float(cross), float(dot)));
|
||||||
// we only want to return only positive angles
|
// we only want to return only positive angles
|
||||||
return angle <= 0 ? angle + 2*PI : angle;
|
return angle <= 0 ? angle + 2*PI : angle;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user