46 Vector &circleBCenter,
long circleBRadius,
55 if ((circleARadius + circleBRadius) < d)
67 a = (circleARadius * circleARadius - circleBRadius * circleBRadius + d * d)/(2 * d);
72 h = circleARadius * circleARadius - a * a;
82 retIntersect1.
x = M.
x + (h * (circleBCenter.
y - circleACenter.
y))/d;
83 retIntersect1.
y = M.
y - (h * (circleBCenter.
x - circleACenter.
x))/d;
84 retIntersect2.
x = M.
x - (h * (circleBCenter.
y - circleACenter.
y))/d;
85 retIntersect2.
y = M.
y + (h * (circleBCenter.
x - circleACenter.
x))/d;
103 long a, b, c, u1, u2, t, distance;
118 a = (B.
x - A.
x) * (B.
x - A.
x) + (B.
y - A.
y) * (B.
y - A.
y);
122 b = 2 * ((B.
x - A.
x) * (A.
x - circle.
x) + (B.
y - A.
y) * (A.
y - circle.
y));
126 c = circle.
x * circle.
x + circle.
y * circle.
y + A.
x * A.
x + A.
y * A.
y -
127 2 * (circle.
x * A.
x + circle.
y * A.
y) - radius * radius;
132 t = b * b - 4 * a * c;
142 u1 = -b * 1000 / (2 * a);
148 u1 = (-b + s) * 1000 / (2 * a);
149 u2 = (-b - s) * 1000 / (2 * a);
152 retIntersect1.
x = A.
x + u1 * (B.
x - A.
x) / 1000;
153 retIntersect1.
y = A.
y + u1 * (B.
y - A.
y) / 1000;
154 retIntersect2.
x = A.
x + u2 * (B.
x - A.
x) / 1000;
155 retIntersect2.
y = A.
y + u2 * (B.
y - A.
y) / 1000;
162 Vector circle, p1, p2, intersect1, intersect2;
170 TEST((success ==
true),
"Intersection");
175 TEST((intersect1.
x == -85),
"intersect1.x");
176 TEST((intersect1.
y == -85),
"intersect1.y");
177 TEST((intersect2.
x == -14),
"intersect2.x");
178 TEST((intersect2.
y == -14),
"intersect2.y");
185 TEST((success ==
true),
"Intersection 2");
190 TEST((intersect1.
x == 30),
"intersect1.x");
191 TEST((intersect1.
y == 0),
"intersect1.y");
192 TEST((intersect2.
x == -30),
"intersect2.x");
193 TEST((intersect2.
y == 0),
"intersect2.y");
bool CircleIntersectLine(Vector &circle, long radius, Vector &pointA, Vector &pointB, Vector &retIntersect1, Vector &retIntersect2)
Determins the 2 points of intersection of a circle and a line given by two vector points...
A vector that represents a 2D point by x-y coordinates and a direction angle.
long VectorGetDistanceVec(Vector &a, Vector &b)
Gets the distance between given two vectors.
void VectorReduce(Vector &a, long S)
Reduces x and y vector components by the given factor. i.e. a = a / S.
Debugging utility macros.
A simple 3-components vector implementation (2D point + direction)
void VectorSubtract(Vector &a, Vector &b)
Subtracts vector b from a. i.e. a -= b.
void VectorScale(Vector &a, long S)
Scales x and y vector components by the given factor. i.e. a = a * S.
bool CircleIntersectCircle(Vector &circleACenter, long circleARadius, Vector &circleBCenter, long circleBRadius, Vector &retIntersect1, Vector &retIntersect2)
Determins the 2 points of intersection of two overlapping circles.
void VectorAdd(Vector &a, Vector &b)
Adds vector b to a. i.e. a += b.
void VectorInit(Vector &a, long x, long y, long theta)
Initializes the vector with given x, y and theta components.