import java.util.Scanner;
class Point {
public double x; // абсцисса точки
public double y; // ордината точки
// возвращает строку с описанием точки
public String toString() {
return "("+x+";"+y+")";
}
// выводит на экран описание точки
public void printPoint() {
System.out.print(this.toString());
}
// метод перемещает точку на указанный вектор
public void movePoint(double a, double b) {
x = x + a;
y = y + b;
}
// метод изменяет координаты точки на указанные
public void setPoint(double a, double b) {
x = a;
y = b;
}
// конструктор по умолчанию, создающий точку в начале координат
public Point() {
System.out.println("Vvedite ordinatu tochki:");
Scanner sc1 = new Scanner(System.in);
if(sc1.hasNextInt()) {
x = sc1.nextInt();
}
System.out.println("Vvedite abstissu tochki:");
Scanner sc2 = new Scanner(System.in);
if(sc2.hasNextInt()) {
y = sc2.nextInt();
}
}
// конструктор, создающий точку с указанными координатами
public Point(double a, double b) {
x = a;
y = b;
}
// метод вычисляющий расстояние между точками
public double length(Point p) {
return Math.sqrt( Math.pow(p.x-x,2) + Math.pow(p.y-y,2) );
}
// метод проверяющий совпадают ли точки
public boolean equalsPoint(Point p) {
if(this.x == p.x && this.y == p.y) {
return true;
} else {
return false;
}
}
public void quarter() {
if(x>0&&y>0) {
System.out.println("Point p2 is in first coordinate quarter");
} else if(x<0&&y>0) {
System.out.println("Point p2 is in second coordinate quarter");
} else if(x<0&&y<0) {
System.out.println("Point p2 is in third coordinate quarter");
} else {
System.out.println("Point p2 is in fourth coordinate quarter");
}
}
public void sim(Point p) {
if(Math.abs(this.x)==Math.abs(p.x)&&Math.abs(this.y)==Math.abs(p.y)) {
System.out.println("Points are symmetrical");
} else {
System.out.println("Points are not symmetrical");
}
}
public boolean koll(Point p1, Point p2) {
double distx1 = this.x-p1.x;
double disty1 = this.y-p1.y;
double distx2 = p1.x-p2.x;
double disty2 = p1.y-p2.y;
double k1 = disty1/distx1;
double k2 = disty2/distx2;
double c1 = this.y-k1*this.x;
double c2 = p2.y-k2*p2.x;
if(k1==k2&&c1==c2) {
System.out.println("Kollinearni");
return true;
} else {
System.out.println("Ne kollinearni");
return false;
}
}
}
class Triangle {
private Point A;
private Point B;
private Point C;
public Triangle() {
Point a = new Point();
Point b = new Point();
Point c = new Point();
if(!a.koll(b,c)) {
A = new Point(a.x, a.y);
B = new Point(b.x, b.y);
C = new Point(c.x, c.y);
} else {
System.out.println("Tochki, zadannije vami, yavljyajytsa kollinearnimi, treugoljnik postroit nevozmojno");
A = new Point(-1, 0);
B = new Point(0, 1);
C = new Point(1, 1);
}
}
public Triangle(double ax, double ay, double bx, double by, double cx, double cy) {
Point a = new Point(ax, ay);
Point b = new Point(bx, by);
Point c = new Point(cx, cy);
if(!a.koll(b,c)) {
A = new Point(ax, ay);
B = new Point(bx, by);
C = new Point(cx, cy);
} else {
System.out.println("Tochki, zadannije vami, yavljyajytsa kollinearnimi, treugoljnik postroit nevozmojno");
A = new Point(-1, 0);
B = new Point(0, 1);
C = new Point(1, 1);
}
}
public String toString() {
return "Treygoljnik s koordinatami vershin: A="+A.toString()+"; B="+B.toString()+"; C="+C.toString()+";";
}
public void print() {
System.out.print(this.toString());
}
public double P() {
double a = Math.sqrt((A.x-B.x)*(A.x-B.x)+(A.y-B.y)*(A.y-B.y));
double b = Math.sqrt((B.x-B.x)*(B.x-C.x)+(B.y-C.y)*(B.y-C.y));
double c = Math.sqrt((A.x-C.x)*(A.x-C.x)+(A.y-C.y)*(A.y-C.y));
/*System.out.println();
System.out.println(a);
System.out.println(b);
System.out.println(c);*/
return a+b+c;
}
public double S() {
double a = Math.sqrt((A.x-B.x)*(A.x-B.x)+(A.y-B.y)*(A.y-B.y));
double b = Math.sqrt((B.x-B.x)*(B.x-C.x)+(B.y-C.y)*(B.y-C.y));
//double c = (A.x-C.x)*(A.x-C.x)+(A.y-C.y)*(A.y-C.y);
double h = Math.abs(a*a-b/2*b/2);
return h*b/2;
}
public Point getA() {
return A;
}
public Point getB() {
return B;
}
public Point getC() {
return C;
}
public void setA(double x, double y) {
Point p = new Point(x,y);
if(!p.koll(B,C)) {
A = p;
} else {
System.out.println("Tochku pomenjat neljza, t. k. ona budet kollinearna k drugim vershinam treugolnika");
}
}
public void setB(double x, double y) {
Point p = new Point(x,y);
if(!p.koll(A,C)) {
B = p;
} else {
System.out.println("Tochku pomenjat neljza, t. k. ona budet kollinearna k drugim vershinam treugolnika");
}
}
public void setC(double x, double y) {
Point p = new Point(x,y);
if(!p.koll(A,B)) {
C = p;
} else {
System.out.println("Tochku pomenjat neljza, t. k. ona budet kollinearna k drugim vershinam treugolnika");
}
}
public void rotate(double deg) {
double rad,cos,sin;
if(deg == 90) {
cos = 0;
sin = 1;
} else {
rad = deg*Math.PI/180;
cos = Math.cos(rad);
sin = Math.sin(rad);
}
double newAx = A.x*cos-A.y*sin;
double newAy = A.x*sin-A.y*cos;
double newBx = B.x*cos-B.y*sin;
double newBy = B.x*sin-B.y*cos;
double newCx = C.x*cos-C.y*sin;
double newCy = C.x*sin-C.y*cos;
A.x = newAx;
A.y = newAy;
B.x = newBx;
B.y = newBy;
C.x = newCx;
C.y = newCy;
/*A.x = A.x*Math.cos(rad)-A.y*Math.sin(rad);
A.y = A.x*Math.sin(rad)-A.y*Math.cos(rad);
B.x = B.x*Math.cos(rad)-B.y*Math.sin(rad);
B.y = B.x*Math.sin(rad)-B.y*Math.cos(rad);
C.x = C.x*Math.cos(rad)-C.y*Math.sin(rad);
C.y = C.x*Math.sin(rad)-C.y*Math.cos(rad);*/
//Triangle tr = new Triangle(A,B,C);
//return tr;
}
}
public class four {
public static void main(String[] args) {
//Triangle abc = new Triangle(1,6,3,2,4,6);
//Triangle abc = new Triangle(1,1,2,2,3,3);
Triangle abc = new Triangle(-1,0,0,1,1,0);
abc.print();
System.out.println("Perimetr treygoljnika raven: "+abc.P());
System.out.println("Ploshad treygoljnika ravna: "+abc.S());
//abc.setA(10,11);
//abc.print();
System.out.println();
System.out.println(Math.sin(Math.PI));
abc.rotate(45);
System.out.println("Rotate 45");
abc.print();
}
}