Advertisement
Niktiaksk

Untitled

Dec 29th, 2021
54
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.63 KB | None | 0 0
  1. package com.company;
  2.  
  3.  
  4. import java.text.DecimalFormat;
  5.  
  6. public class Vector {
  7.     private int x_;
  8.     private int y_;
  9.     private int z_;
  10.  
  11.     Vector(int x, int y, int z) {
  12.         x_ = x;
  13.         y_ = y;
  14.         z_ = z;
  15.     }
  16.  
  17.     void calculateLength() {
  18.         String formattedDouble = new DecimalFormat("#0.00").format(Math.sqrt(Double.valueOf(x_ * x_ + y_ * y_ + z_ * z_)));
  19.         System.out.println("length = " + formattedDouble);
  20.     }
  21.  
  22.     double calculate() {
  23.         return (Math.sqrt(Double.valueOf(x_ * x_ + y_ * y_ + z_ * z_)));
  24.     }
  25.  
  26.     void print() {
  27.         System.out.println("(" + x_ + " , " + y_ + " , " + z_ + ")");
  28.     }
  29.  
  30.     Vector sumOfVectors(Vector vector) {
  31.         return new Vector(this.x_ + vector.x_, this.y_ + y_, this.z_ + vector.z_);
  32.     }
  33.  
  34.     Vector differenceOfVectors(Vector vector) {
  35.         return new Vector(
  36.                 this.x_ - vector.x_, this.y_ - y_, this.z_ - vector.z_
  37.         );
  38.     }
  39.  
  40.     int scMultiplyOfVector(Vector vector) {
  41.         return this.x_ * vector.x_ + this.y_ * y_ + this.z_ * vector.z_;
  42.     }
  43.  
  44.     double vcMultiplyOfVectors(Vector vector) {
  45.         return this.scMultiplyOfVector(vector) * this.foundSin(vector);
  46.     }
  47.  
  48.     double foundCos(Vector vector) {
  49.         return (this.scMultiplyOfVector(vector) / (this.calculate() * vector.calculate()));
  50.     }
  51.  
  52.     double foundSin(Vector vector) {
  53.         return Math.sqrt(1 - this.foundAngle(vector) * this.foundAngle(vector));
  54.     }
  55.  
  56.     int foundAngle(Vector vector) {
  57.         return (int) Math.acos((this.scMultiplyOfVector(vector) / (this.calculate() * vector.calculate())));
  58.     }
  59. }
  60.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement