1 8 package org.lsmp.djep.groupJep.groups; 9 10 import org.nfunk.jep.JEP; 11 import org.lsmp.djep.groupJep.interfaces.*; 12 18 public class Quartonians extends Group implements RingI { 19 20 public static class Quartonian extends Number { 21 double x,y,z,w; 22 public Quartonian(double x,double y,double z,double w){ 23 this.w = x; this.y = y; this.z=z; this.w=w; 24 } 25 public double doubleValue() {return x;} 26 public float floatValue() {return (float) x;} 27 public int intValue() {return (int) x;} 28 public long longValue() {return (long) x;} 29 public String toString() {return ""+x+"+"+y+" i +"+z+" j +"+w+" k"; 31 34 } 35 } 36 private Quartonian ZERO = new Quartonian(0,0,0,0); 37 private Quartonian ONE = new Quartonian(1,0,0,0); 38 private Quartonian I = new Quartonian(0,1,0,0); 39 private Quartonian J = new Quartonian(0,0,1,0); 40 private Quartonian K = new Quartonian(0,0,0,1); 41 42 public Number getZERO() {return ZERO;} 43 public Number getONE() {return ONE; } 44 45 public Number getInverse(Number num) { 46 Quartonian q = (Quartonian) num; 47 return new Quartonian(-q.x,-q.y,-q.z,-q.w); 48 } 49 50 public Number add(Number a, Number b) { 51 Quartonian p = (Quartonian) a; 52 Quartonian q = (Quartonian) b; 53 return new Quartonian(p.x+q.x,p.y+q.y,p.z+q.z,p.w+q.w); 54 } 55 56 public Number sub(Number a, Number b) { 57 Quartonian p = (Quartonian) a; 58 Quartonian q = (Quartonian) b; 59 return new Quartonian(p.x-q.x,p.y-q.y,p.z-q.z,p.w-q.w); 60 } 61 62 63 public Number mul(Number a, Number b) { 64 Quartonian p = (Quartonian) a; 65 Quartonian q = (Quartonian) b; 66 return new Quartonian( 67 p.x*q.x - p.y*q.y - p.z*q.z - p.w*q.w, 68 p.x*q.y - p.y*q.x + p.z*q.w - p.w*q.z, 69 p.x*q.z - p.y*q.w + p.z*q.x + p.w*q.y, 70 p.x*q.w - p.y*q.z - p.z*q.y + p.w*q.x 71 ); 72 } 73 74 public boolean equals(Number a, Number b) { 75 Quartonian p = (Quartonian) a; 76 Quartonian q = (Quartonian) b; 77 return (p.x==q.x)&&(p.y==q.y)&&(p.z==q.z)&&(p.w==q.w); 78 } 79 80 public Number valueOf(String s) { 81 return new Quartonian(Double.parseDouble(s),0,0,0); 82 } 83 84 public void addStandardConstants(JEP j) { 85 super.addStandardConstants(j); 86 j.addConstant("i",I); 87 j.addConstant("j",J); 88 j.addConstant("k",K); 89 } 90 public String toString() {return "quaternions";} 91 92 } 93 | Popular Tags |