SHARE
TWEET

korzystaj mądrze

a guest Oct 21st, 2019 71 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. package com.company;
  2.  
  3. import javax.crypto.spec.IvParameterSpec;
  4.  
  5. public interface IVector {
  6.     public double getAbs();
  7.     public double getVx();
  8.     public double getVy();
  9.     public void setVx(double vx);
  10.     public void setVy(double vy);
  11.  
  12.     static double dotProduct(IVector a, IVector b) {
  13.  
  14.         double dot = (a.getVx() * b.getVx() + a.getVy() * b.getVy());
  15.  
  16.         if (a instanceof Vector3D && b instanceof Vector3D)    {
  17.             dot += (((Vector3D)a).getVz() * ((Vector3D)b).getVz());
  18.             return dot;
  19.         }
  20.         return dot;
  21.     }
  22.  
  23.     static IVector crossProduct(IVector a, IVector b)   {
  24.         if (a instanceof Vector && b instanceof Vector) {
  25.  
  26.             double vz = (a.getVx() * b.getVy() - a.getVy()*b.getVx());
  27.  
  28.             return new Vector3D(0, 0, vz);
  29.         }   else if(a instanceof Vector3D && b instanceof Vector3D) {
  30.  
  31.             double vx = (a.getVy() * ((Vector3D) b).getVz() - ((Vector3D) a).getVz()*b.getVy());
  32.             double vy = (((Vector3D) a).getVz() * b.getVx() - a.getVx()*((Vector3D) b).getVz());
  33.             double vz = (a.getVx() * b.getVy() - a.getVy()*b.getVx());
  34.  
  35.             return (IVector)new Vector3D(vx, vy, vz);
  36.         }
  37.         final IVector c = null;
  38.         return c;
  39.     }
  40.  
  41.     static IVector addVectors(IVector a, IVector b) {
  42.         double vx = a.getVx() + b.getVx();
  43.         double vy = a.getVy() + b.getVy();
  44.  
  45.         if(a instanceof Vector3D && b instanceof Vector3D)  {
  46.             double vz = (((Vector3D) a).getVz() + ((Vector3D) b).getVz());
  47.             return (IVector)new Vector3D(vx, vy, vz);
  48.         }
  49.         return (IVector)new Vector(vx, vy);
  50.     }
  51.  
  52.     static IVector subtractVectors(IVector a, IVector b) {
  53.  
  54.         double vx = a.getVx() - b.getVx();
  55.         double vy = a.getVy() - b.getVy();
  56.  
  57.         if(a instanceof Vector3D && b instanceof Vector3D) {
  58.             double vz = ((Vector3D) a).getVz() - ((Vector3D) b).getVz();
  59.             return (IVector)new Vector3D(vx, vy, vz);
  60.         }
  61.         return (IVector)new Vector(vx, vy);
  62.     }
  63.  
  64.     static IVector multiplyVectorByNumber(IVector a, double number) {
  65.  
  66.         double vx = a.getVx() * number;
  67.         double vy = a.getVy() * number;
  68.  
  69.         if(a instanceof Vector3D) {
  70.             double vz = ((Vector3D) a).getVz() * number;
  71.             return (IVector)new Vector3D(vx, vy, vz);
  72.         }
  73.         return (IVector)new Vector(vx, vy);
  74.     }
  75. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top