Merge branch 'ahmed' into 'main'
This commit is contained in:
@@ -4,19 +4,23 @@
|
||||
struct Obstacle {
|
||||
Vector2d start;
|
||||
Vector2d end;
|
||||
Vector2d obstacle_v;
|
||||
|
||||
Obstacle() : start(0, 0), end(0, 0) {}
|
||||
Obstacle(Vector2d s, Vector2d e) : start(s), end(e) {}
|
||||
double length_sq_inv;
|
||||
|
||||
Obstacle() : start(0, 0), end(0, 0), obstacle_v(0, 0), length_sq_inv(0.0) {}
|
||||
Obstacle(Vector2d s, Vector2d e) : start(s), end(e) {
|
||||
obstacle_v = end - start;
|
||||
double length_sq = obstacle_v.dot(obstacle_v);
|
||||
length_sq_inv = length_sq != 0 ? 1.0 / length_sq : 0.0;
|
||||
}
|
||||
|
||||
// Find the point of the obstacle that is closest to p
|
||||
// # 8 ADDs, 6 MULTs, 1 DIV
|
||||
// # 5 ADDs, 5 MULTs
|
||||
Vector2d find_nearest_obstacle_point(Vector2d p) {
|
||||
|
||||
// # 2 ADDs
|
||||
Vector2d obstacle_v = end - start;
|
||||
|
||||
// # 4 ADDs, 4 MULTs, 1 DIV
|
||||
double projection = (p - start).dot(obstacle_v) / obstacle_v.dot(obstacle_v);
|
||||
// # 3 ADDs, 3 MULTs
|
||||
double projection = (p - start).dot(obstacle_v) * length_sq_inv;
|
||||
|
||||
if (projection < 0.0)
|
||||
projection = 0.0;
|
||||
|
||||
Reference in New Issue
Block a user