Advertisement
O_Egor

laba4(Trapezoid)

Mar 22nd, 2020
374
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.81 KB | None | 0 0
  1. package com.company;
  2.  
  3. public class Trapezoid {
  4.     double x1, y1, z1;
  5.     double x2, y2, z2;
  6.     double x3, y3, z3;
  7.     double x4, y4, z4;
  8.     boolean flag;
  9.  
  10.     public boolean isFigure() {
  11.         double xx1 = Math.abs(x1 - x2), yy1 = Math.abs(y1 - y2), zz1 = Math.abs(z1 - z2);
  12.         double xx2 = Math.abs(x2 - x3), yy2 = Math.abs(y2 - y3), zz2 = Math.abs(z2 - z3);
  13.         double xx3 = Math.abs(x3 - x4), yy3 = Math.abs(y3 - y4), zz3 = Math.abs(z3 - z4);
  14.         double xx4 = Math.abs(x4 - x1), yy4 = Math.abs(y4 - y1), zz4 = Math.abs(z4 - z1);
  15.  
  16.         if     (Math.abs((xx1 * xx3 + yy1 * yy3 + zz1 * zz3) / (Math.sqrt(xx1 * xx1 + yy1 * yy1 + zz1 * zz1) * Math.sqrt(xx3 * xx3 + yy3 * yy3 + zz3 * zz3))) == 1
  17.                 &&
  18.                 Math.abs((xx2 * xx4 + yy2 * yy4 + zz2 * zz4) / (Math.sqrt(xx2 * xx2 + yy2 * yy2 + zz2 * zz2) * Math.sqrt(xx4 * xx4 + yy4 * yy4 + zz4 * zz4))) != 1) {
  19.             flag = true;
  20.         }
  21.         else {
  22.             flag = false;
  23.         }
  24.  
  25.         return flag;
  26.     }
  27.  
  28.     public double getSquare(){
  29.         double FinalSquare;
  30.         if(flag){
  31.             Dot Vector1 = new Dot(Math.abs(x3 - x4), Math.abs(y3 - y4), Math.abs(z3 - z4)),
  32.                 Vector2 = new Dot(Math.abs(x4 - x1), Math.abs(y4 - y1), Math.abs(z4 - z1)),
  33.                 Vector3 = new Dot(Math.abs(x1 - x2), Math.abs(y1 - y2), Math.abs(z1 - z2));
  34.             Dot square = new Dot((Vector1.y * Vector2.z - Vector1.z * Vector2.y), (Vector1.x * Vector2.z - Vector1.z * Vector2.x), (Vector1.x * Vector2.y - Vector1.y * Vector2.x));
  35.             double base1 = (Math.sqrt(Vector1.x * Vector1.x + Vector1.y * Vector1.y + Vector1.z * Vector1.z)),
  36.                    base2 = (Math.sqrt(Vector3.x * Vector3.x + Vector3.y * Vector3.y + Vector3.z * Vector3.z));
  37.             double height = (Math.sqrt(square.x * square.x + square.y * square.y + square.z * square.z)) / base1;
  38.             FinalSquare = (base1 + base2) * 0.5 * height;
  39.         }
  40.         else{
  41.             System.out.println("ERROR!!!");
  42.             FinalSquare = -1337;
  43.         }
  44.         return FinalSquare;
  45.     }
  46.  
  47.     public Trapezoid(Dot A, Dot B, Dot C, Dot D){
  48.         this.x1 = A.x; this.y1 = A.y; this.z1 = A.z;
  49.         this.x2 = B.x; this.y2 = B.y; this.z2 = B.z;
  50.         this.x3 = C.x; this.y3 = C.y; this.z3 = C.z;
  51.         this.x4 = D.x; this.y4 = D.y; this.z4 = D.z;
  52.     }
  53.  
  54.     public Trapezoid(double x1, double y1, double z1,
  55.                      double x2, double y2, double z2,
  56.                      double x3, double y3, double z3,
  57.                      double x4, double y4, double z4){
  58.         this.x1 = x1; this.y1 = y1; this.z1 = z1;
  59.         this.x2 = x2; this.y2 = y2; this.z2 = z2;
  60.         this.x3 = x3; this.y3 = y3; this.z3 = z3;
  61.         this.x4 = x4; this.y4 = y4; this.z4 = z4;
  62.     }
  63.  
  64.     public Trapezoid(){
  65.     }
  66.  
  67. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement