Haifisch7734

Zad3

Mar 19th, 2014
50
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.45 KB | None | 0 0
  1. package zad3;
  2.  
  3. import static java.lang.Math.*;
  4.  
  5. public class Wektor {
  6.  
  7.     private double xP = 0;
  8.     private double yP = 0;
  9.     private double xK;
  10.     private double yK;
  11.     private double dlugosc;
  12.     private double kat;
  13.    
  14.     private static Wektor d1k0 = new Wektor(1,0,1,0);
  15.     private static Wektor d1k90 = new Wektor(0,1,1,90);
  16.     private static Wektor d1k180 = new Wektor(-1,0,1,180);
  17.     private static Wektor d1k270 = new Wektor(0,-1,1,270);
  18.    
  19.     public Wektor(){
  20.        
  21.     }
  22.    
  23.     public static Wektor stworz(double param1, double param2, boolean konWek){
  24.         if (konWek == true){
  25.             double xk = param1;
  26.             double yk = param2;
  27.             double dl = sqrt(xk*xk+yk*yk);
  28.             double kat = atan(yk/xk);
  29.             return new Wektor(xk,yk,dl,kat);
  30.         }
  31.         else{
  32.             if (param1 == 1){
  33.                 int x = (int)param2;
  34.                 switch(x){
  35.                     case 0:     return d1k0;
  36.                     case 90:    return d1k90;
  37.                     case 180:   return d1k180;
  38.                     case 270:   return d1k270;
  39.                 }
  40.                 double a = tan(param2);
  41.                 double xk = sqrt(1/(1+a*a));
  42.                 double yk = a*x;
  43.                 double dl = param1;
  44.                 double kat = param2;
  45.                 return new Wektor(xk,yk,dl,kat);
  46.             }
  47.         return new Wektor(0,0,0,0);
  48.         }
  49.     }
  50.    
  51.     private Wektor(double xk, double yk, double dl, double kat){
  52.         this.xK = xk;
  53.         this.yK = yk;
  54.         this.dlugosc = dl;
  55.         this.kat = kat;
  56.     }
  57.    
  58.     public double zwrdl(){
  59.         return this.dlugosc;
  60.     }
  61.     public static void main(String[] args){
  62.         Wektor nowy = Wektor.stworz(1,2,true);
  63.         System.out.println(nowy.zwrdl());
  64.  
  65.     }
  66. }
Advertisement
Add Comment
Please, Sign In to add comment