1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167
|
import java.io.*; import java.util.*;
public class Main {
final static double eps = 1e-5; final static double pi = Math.acos(-1.0);
static int dcmp(double d) { if (Math.abs(d) < eps) return 0; return d > 0 ? 1 : -1; }
public static void main(String[] args) throws IOException { InputReader in = new InputReader(System.in); PrintWriter out = new PrintWriter(System.out); int T = in.nextInt(); while (T-- > 0) { int n = in.nextInt(); Point p1 = new Point(0, 0), q1 = new Point(p1); Point p2 = new Point(0, 1), q2 = new Point(p2); for (int i = 1; i <= n; i++) { double x = in.nextDouble(); double y = in.nextDouble(); double a = in.nextDouble(); q1 = q1.rotate(x, y, a); q2 = q2.rotate(x, y, a); } Vector v1 = new Vector(p1, q1).normal(); Vector v2 = new Vector(p2, q2).normal(); Point o = Vector.GetLineIntersection(Point.mid(p1, q1), v1, Point.mid(p2, q2), v2); double ans = Vector.angle(o, p1, q1); if (Vector.cross(new Vector(o, p1), new Vector(o, q1)) < 0) ans = 2 * pi - ans; out.printf("%.5f %.5f %.5f\n", o.x, o.y, ans); } out.flush(); out.close(); }
static class Point { double x, y;
Point() { }
Point(double _x, double _y) { x = _x; y = _y; }
Point(Point p) { this(p.x, p.y); }
boolean equals(Point p) { return dcmp(x - p.x) == 0 && dcmp(y - p.y) == 0; }
Point add(Point r) { return new Point(x + r.x, y + r.y); }
Point sub(Point r) { return new Point(x - r.x, y - r.y); }
Point mul(double r) { return new Point(x * r, y * r); }
Point move(double dx, double dy) { return new Point(x + dx, y + dy); }
Point rotate(double a) { return new Point(x * Math.cos(a) - y * Math.sin(a), x * Math.sin(a) + y * Math.cos(a)); }
Point rotate(double dx, double dy, double a) { return this.move(-dx, -dy).rotate(a).move(dx, dy); }
static Point mid(Point a, Point b) { return new Point((a.x + b.x) / 2.0, (a.y + b.y) / 2.0); } }
static class Vector extends Point { Vector(double _x, double _y) { x = _x; y = _y; }
Vector(Point a, Point b) { this(b.x - a.x, b.y - a.y); }
Vector(Point p) { this(p.x, p.y); }
static double angle(Vector a, Vector b) { return Math.acos(dot(a, b) / a.length() / b.length()); }
static double angle(Point o, Point a, Point b) { return angle(new Vector(o, a), new Vector(o, b)); }
double dot(Vector r) { return x * r.x + y * r.y; }
double cross(Vector r) { return x * r.y - y * r.x; }
double length() { return Math.sqrt(this.dot(this)); }
Vector normal() { double len = this.length(); return new Vector(-y / len, x / len); }
static Point GetLineIntersection(Point p, Vector v, Point q, Vector w) { Vector u = new Vector(p.sub(q)); double t = cross(w, u) / cross(v, w); return p.add(v.mul(t)); }
static Point GetLineIntersection(Point p, Point v, Point q, Point w) { return GetLineIntersection(p, new Vector(v), q, new Vector(w)); }
static Vector add(Vector a, Vector b) { return new Vector(a.add(b)); }
static double dot(Vector a, Vector b) { return a.dot(b); }
static double cross(Vector a, Vector b) { return a.cross(b); }
static double cross(Point o, Point a, Point b) { return cross(new Vector(o, a), new Vector(o, b)); }
static double length(Vector r) { return r.length(); } } }
|