Skip to content
This repository was archived by the owner on Apr 9, 2024. It is now read-only.

Commit 84b81db

Browse files
Update Circle
1 parent fd2d663 commit 84b81db

File tree

2 files changed

+8
-2
lines changed

2 files changed

+8
-2
lines changed

Geometry/Circle.cpp

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,11 @@ Point circumCenter(Point a, Point b, Point c) {
88
return a + (b * sq(c) - c * sq(b)).perp() / b.cross(c) / 2;
99
}
1010

11+
// Retorna el punto que se encuentra en el circulo dado el angulo
12+
Point circlePoint(Point c, double r, double ang) {
13+
return Point{c.x + cos(ang) * r, c.y + sin(ang) * r};
14+
}
15+
1116
// Retorna el numero de intersecciones de la linea l con el circulo (o,r)
1217
// y los pone en out. Si solo hay una interseccion el par de out es igual
1318
int circleLine(Point o, double r, Line l, pair<Point, Point> &out) {
@@ -24,7 +29,7 @@ int circleLine(Point o, double r, Line l, pair<Point, Point> &out) {
2429
// la interseccion con una linea
2530
int circleCircle(Point o1, double r1, Point o2, double r2, pair<Point, Point> &out) {
2631
Point d = o2 - o1;
27-
double d2 = sq(d);
32+
double d2 = d.sq();
2833
if (d2 == 0) {
2934
assert(r1 != r2); // los circulos son iguales
3035
return 0;

Geometry/Point.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,12 +37,13 @@ struct Point {
3737
Point translate(Point v) { return *this + v; }
3838
Point scale(Point c, double factor) { return c + (*this - c) * factor; }
3939
Point rotate(double ang) { return {x * cos(ang) - y * sin(ang), x * sin(ang) + y * cos(ang)}; }
40-
Point rot_around(double ang, Point c) { return p + (*this - p).rotate(ang); }
40+
Point rot_around(double ang, Point c) { return c + (*this - c).rotate(ang); }
4141
Point perp() { return {-y, x}; }
4242

4343
T dot(Point p) { return x * p.x + y * p.y; }
4444
T cross(Point p) const { return x * p.y - y * p.x; }
4545
T cross(Point a, Point b) const { return (a - *this).cross(b - *this); }
46+
double angle() const { return atan2(y, x); }
4647

4748
friend ostream& operator<<(ostream& os, Point p) {
4849
return os << "(" << p.x << "," << p.y << ")";

0 commit comments

Comments
 (0)