Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package zad3;
- import static java.lang.Math.*;
- public class Wektor {
- private double xP = 0;
- private double yP = 0;
- private double xK;
- private double yK;
- private double dlugosc;
- private double kat;
- private static Wektor d1k0 = new Wektor(1,0,1,0);
- private static Wektor d1k90 = new Wektor(0,1,1,90);
- private static Wektor d1k180 = new Wektor(-1,0,1,180);
- private static Wektor d1k270 = new Wektor(0,-1,1,270);
- public Wektor(){
- }
- public static Wektor stworz(double param1, double param2, boolean konWek){
- if (konWek == true){
- double xk = param1;
- double yk = param2;
- double dl = sqrt(xk*xk+yk*yk);
- double kat = atan(yk/xk);
- return new Wektor(xk,yk,dl,kat);
- }
- else{
- if (param1 == 1){
- int x = (int)param2;
- switch(x){
- case 0: return d1k0;
- case 90: return d1k90;
- case 180: return d1k180;
- case 270: return d1k270;
- }
- double a = tan(param2);
- double xk = sqrt(1/(1+a*a));
- double yk = a*x;
- double dl = param1;
- double kat = param2;
- return new Wektor(xk,yk,dl,kat);
- }
- return new Wektor(0,0,0,0);
- }
- }
- private Wektor(double xk, double yk, double dl, double kat){
- this.xK = xk;
- this.yK = yk;
- this.dlugosc = dl;
- this.kat = kat;
- }
- public double zwrdl(){
- return this.dlugosc;
- }
- public static void main(String[] args){
- Wektor nowy = Wektor.stworz(1,2,true);
- System.out.println(nowy.zwrdl());
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment