Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package geometrie;
- import java.io.FileNotFoundException;
- import java.util.Scanner;
- public class Tema4 {
- public static void main(String[] args) {
- Scanner in;
- try {
- in = new Scanner(new java.io.File("date.in"));
- Point[] points = new Point[4];
- double x, y;
- for (int i = 0; i < 4; i++) {
- x = in.nextDouble();
- y = in.nextDouble();
- points[i] = new Point(x, y);
- }
- // Ecuatia dreptei punctelor 1 si 2
- double a12 = points[1].y - points[2].y;
- double b12 = points[2].x - points[1].x;
- Point mid12 = new Point((points[1].x + points[2].x) / 2, (points[1].y + points[2].y) / 2);
- double d12 = -(b12 * mid12.x + a12 * mid12.y);
- // Ecuatia dreptei punctelor 2 si 0
- double a20 = points[2].y - points[0].y;
- double b20 = points[2].x - points[0].x;
- Point mid20 = new Point((points[2].x + points[0].x) / 2, (points[2].y + points[0].y) / 2);
- double d20 = -(b20 * mid20.x + a20 * mid20.y);
- // Delta
- double delta = (a12 * b20) - (a20 * b12);
- double d1 = (d20 * b12) - (d12 * b20);
- double d2 = (a20 * d12) - (a12 * d20);
- // Centrul cercului circumscris
- Point center = new Point(d1 / delta, d2 / delta);
- System.out.println("Center " + center);
- // Raza
- double radius = distance(center, points[0]);
- System.out.println("Radius " + radius);
- double t1 = points[3].x - center.x;
- double t2 = points[3].y - center.y;
- if (t1 * t1 + t2 * t2 < radius * radius) {
- System.out.println("4th point inside circle");
- } else {
- System.out.println("4th point on circle");
- }
- } catch (FileNotFoundException ex) {
- System.out.println("File not found!");
- }
- }
- private static double distance(Point p1, Point p2) {
- double t1 = p2.x - p1.x;
- double t2 = p2.y - p1.y;
- System.out.println("t1 " + t1);
- System.out.println("t2 " + t2);
- return Math.sqrt((t1 * t1) + (t2 * t2));
- }
- private static Point vector(Point p1, Point p2) {
- return new Point(p2.x - p1.x, p2.y - p1.y);
- }
- private static double scalar(Point p1, Point p2) {
- return p1.x * p2.x + p1.y * p2.y;
- }
- private static double norm(Point p) {
- return Math.sqrt(p.x * p.x + p.y * p.y);
- }
- static class Point implements Comparable {
- double x, y;
- Point(double x, double y) {
- this.x = x;
- this.y = y;
- }
- boolean between(Point p1, Point p2) {
- double minx = (p1.x < p2.x) ? p1.x : p2.x;
- double maxx = (p1.x > p2.x) ? p1.x : p2.x;
- double miny = (p1.y < p2.y) ? p1.y : p2.y;
- double maxy = (p1.y > p2.y) ? p1.y : p2.y;
- if ((this.x >= minx && this.x <= maxx) && (this.y >= miny && this.y <= maxy)) {
- return true;
- }
- return false;
- }
- @Override
- public int compareTo(Object o) {
- Point p = (Point) o;
- if (x > p.x) {
- return 1;
- } else if (x == p.x) {
- if (y > p.y) {
- return 1;
- } else if (y == p.y) {
- return 0;
- } else {
- return -1;
- }
- }
- return -1;
- }
- @Override
- public String toString() {
- return "Point{" + "x=" + x + ", y=" + y + '}';
- }
- public Point copy() {
- return new Point(x, y);
- }
- @Override
- public boolean equals(Object obj) {
- if (obj == null) {
- return false;
- }
- if (getClass() != obj.getClass()) {
- return false;
- }
- final Point other = (Point) obj;
- if (Double.doubleToLongBits(this.x) != Double.doubleToLongBits(other.x)) {
- return false;
- }
- if (Double.doubleToLongBits(this.y) != Double.doubleToLongBits(other.y)) {
- return false;
- }
- return true;
- }
- }
- }
Add Comment
Please, Sign In to add comment