Advertisement
FedchenkoIhor

vector

Sep 26th, 2016
106
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.61 KB | None | 0 0
  1. package app;
  2. /**
  3.  *
  4.  * @author Ihor Fedchenko
  5.  *
  6.  */
  7. public class Vector {
  8.     /**
  9.      *
  10.      */
  11.     double x1;
  12.     /**
  13.      *
  14.      */
  15.     double x2;
  16.     /**
  17.      *
  18.      */
  19.     double x3;
  20.     /**
  21.      *
  22.      */
  23.     Vector() {
  24.     x1 = 0.0;
  25.     x2 = 0.0;
  26.     x3 = 0.0;
  27.     }
  28.     /**
  29.      *
  30.      * @param x1
  31.      * @param x2
  32.      * @param x3
  33.      */
  34.     Vector(double x1, double x2, double x3) {
  35.     this.x1 = x1;
  36.     this.x2 = x2;
  37.     this.x3 = x3;
  38.     }
  39.  
  40.     double getX1() {
  41.     return x1;
  42.     }
  43.  
  44.     void setX1(double x1) {
  45.     this.x1 = x1;
  46.     }
  47.  
  48.     double getX2() {
  49.     return x2;
  50.     }
  51.  
  52.     void setX2(double x2) {
  53.     this.x2 = x2;
  54.     }
  55.  
  56.     double getX3() {
  57.     return x3;
  58.     }
  59.  
  60.     void setX3(double x3) {
  61.     this.x3 = x3;
  62.     }
  63.     /**
  64.      *
  65.      * @param value
  66.      * @return
  67.      */
  68.     Vector getVectorSum(Vector value) {
  69.     return new Vector(this.x1 + value.getX1(), this.x2 + value.getX2(), this.x3 + value.getX3());
  70.     }
  71.     /**
  72.      *
  73.      * @param value
  74.      * @return
  75.      */
  76.     double getScalarProguct(Vector value) {
  77.     return ((this.x1 * value.getX1()) + (this.x2 * value.getX2()) + (this.x3 * value.getX3()));
  78.     }
  79.     /**
  80.      *
  81.      * @param value
  82.      * @return
  83.      */
  84.     Vector get2VectorsProguct(Vector value) {
  85.     return new Vector(this.x2 * value.getX3() - this.x3 * value.getX2(), this.x3 * value.getX1() - this.x1 * value.getX3(),
  86.         this.x1 * value.getX2() - this.x2 * value.getX1());
  87.     }
  88.     /**
  89.      *
  90.      * @return
  91.      */
  92.     double getModule() {
  93.     return Math.sqrt((this.x1*=this.x1)+(this.x2*=this.x2)+(this.x3*=this.x3));
  94.     }
  95.  
  96. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement