added new helper methods
worked on gridWalker v3
This commit is contained in:
@@ -5,6 +5,7 @@
|
||||
|
||||
#include "Point2.h"
|
||||
#include "Ray2.h"
|
||||
#include "Line2.h"
|
||||
|
||||
#include "../Assertions.h"
|
||||
|
||||
@@ -65,6 +66,24 @@ public:
|
||||
|
||||
}
|
||||
|
||||
/** does this circle intersect with the given ray? */
|
||||
bool intersects(const Line2 line) const {
|
||||
|
||||
// https://math.stackexchange.com/questions/311921/get-location-of-vector-circle-intersection
|
||||
Point2 dir = line.p2 - line.p1;
|
||||
Point2 start = line.p1;
|
||||
const float a = dir.x*dir.x + dir.y*dir.y;
|
||||
const float b = 2 * dir.x * (start.x-center.x) + 2 * dir.y * (start.y - center.y);
|
||||
const float c = (start.x-center.x) * (start.x-center.x) + (start.y - center.y)*(start.y - center.y) - radius*radius;
|
||||
const float discr = b*b - 4*a*c;
|
||||
|
||||
if (discr < 0) {return false;}
|
||||
|
||||
const float t = (2*c) / (-b + std::sqrt(discr));
|
||||
return (t <= 1) && (t >= 0);
|
||||
|
||||
}
|
||||
|
||||
|
||||
/** configure this sphere to contain the given point-set */
|
||||
void adjustToPointSet(const std::vector<Point2>& lst) {
|
||||
|
||||
Reference in New Issue
Block a user