Maths - 3d multivector Code - Java

 related classes

/*Title:      mjbWorld
Copyright (c) 1998-2003 Martin John BakerThis program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version.This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.For information about the GNU General Public License see http://www.gnu.org/To discuss this program http://sourceforge.net/forum/forum.php?forum_id=122133 also see website https://www.euclideanspace.com/ */package mjbModel;/** * a class to represent a 3d multivector (clifford / geometric algebra) as described here: * https://www.euclideanspace.com/maths/algebra/clifford/index.htm */ public class sfmulti3d extends property { public double e; // scalar public double ex,ey,ez; // vector ex = e1,ey = e2 ,ez = e3 public double exy,ezx,eyz; // bivector exy = e1 ^ e2 ,ezx = e3 ^ e1 ,eyz = e2 ^ e3 public double exyz; // trivector exyz = e1 ^ e2 ^ e3 /** * null constructor * creates class with all zero elements */ public sfmulti3d() { super(); } /** * copy constructor * creates class with elements set to same value as other class * @param other class to copy */ public sfmulti3d(sfmulti3d other) { // copy constructor e = other.e; ex = other.ex; ey = other.ey; ez = other.ez; exy = other.exy; ezx = other.ezx; eyz = other.eyz; exyz = other.exyz; } /** * generates an array * @return array containing equivelant matrix */ public double[] toMatrix(){ // under construction double[] matrix = new double[16]; try { matrix[0] = 0; matrix[1] = 0; matrix[2] = 0; matrix[3] = 0; matrix[4] = 0; matrix[5] = 0; matrix[6] = 0; matrix[7] = 0; matrix[8] = 0; matrix[9] = 0; matrix[10] = 0; matrix[11] = 0; matrix[12] = 0; matrix[13] = 0; matrix[14] = 0; matrix[15] = 0; } catch (Exception e1) { System.out.println("sfmulti3d.toMatrix " + e1 +outstring(0)); } return matrix; }/** * returns a string containing the name of this type * cant use static method below when we need to override property.vrmlType() method * @return name of this type "sfmulti3d" */ public String vrmlType(){ return "sfmulti3d"; } /** * a static method to get a string containing the name of this type * @return name of this type "sfmulti3d" */ public static String vrmlType_s(){ return "sfmulti3d"; } /** * override clone method * @return clone of this method */ public Object clone() { return new sfmulti3d(this); }/** * add other multivector to this one * other is not altered * for theory see: * https://www.euclideanspace.com/maths/algebra/clifford/arithmetic/index.htm * @param other the multivector to be added to this, other is not altered */ public void add(sfmulti3d other) { e += other.e; ex += other.ex; ey += other.ey; ez += other.ez; exy += other.exy; ezx += other.ezx; eyz += other.eyz; exyz += other.exyz; } /** * subtract other multivector from this one * other is not altered * for theory see: * https://www.euclideanspace.com/maths/algebra/clifford/arithmetic/index.htm * @param other the multivector to be subtracted from this, other is not altered */ public void sub(sfmulti3d other) { e -= other.e; ex -= other.ex; ey -= other.ey; ez -= other.ez; exy -= other.exy; ezx -= other.ezx; eyz -= other.eyz; exyz -= other.exyz; }/** * multiply another multivector with this one * other is not altered * for theory see: * https://www.euclideanspace.com/maths/algebra/clifford/arithmetic/index.htm * @param other the multivector to be multiplied by this, other is not altered */ public void mult(sfmulti3d other) { sfmulti3d tmp = new sfmulti3d(this); mult(tmp,other); }/** * set this multivector to a * b * a and b are not altered * for theory see: * https://www.euclideanspace.com/maths/algebra/clifford/arithmetic/index.htm * @param a the first multivector to be multiplied, it is not altered * @param b the second multivector to be multiplied, it is not altered */ public void mult(sfmulti3d a,sfmulti3d b) { e = a.e * b.e + a.ex * b.ex + a.ey * b.ey + a.ez * b.ez - a.exy * b.exy - a.ezx * b.ezx - a.eyz * b.eyz - a.exyz * b.exyz; ex = a.ex * b.e + a.e * b.ex - a.exy * b.ey + a.ezx * b.ez + a.ey * b.exy - a.ez * b.ezx - a.exyz * b.eyz - a.eyz * b.exyz; ey = a.ey * b.e + a.exy * b.ex + a.e * b.ey - a.eyz * b.ez - a.ex * b.exy - a.exyz * b.ezx + a.ez * b.eyz - a.ezx * b.exyz; ez = a.ez * b.e - a.ezx * b.ex + a.eyz * b.ey + a.e * b.ez - a.exyz * b.exy + a.ex * b.ezx - a.ey * b.eyz - a.exy * b.exyz; exy = a.exy * b.e + a.ey * b.ex - a.ex * b.ey + a.exyz * b.ez + a.e * b.exy + a.eyz * b.ezx - a.ezx * b.eyz + a.ez * b.exyz; ezx = a.ezx * b.e - a.ez * b.ex + a.exyz * b.ey + a.ex * b.ez - a.eyz * b.exy + a.e * b.ezx + a.exy * b.eyz + a.ey * b.exyz; eyz = a.eyz * b.e + a.exyz * b.ex + a.ez * b.ey - a.ey * b.ez + a.ezx * b.exy - a.exy * b.ezx + a.e * b.eyz + a.ex * b.exyz; exyz =a.exyz * b.e + a.eyz * b.ex + a.ezx * b.ey + a.exy * b.ez + a.ez * b.exy + a.ey * b.ezx + a.ex * b.eyz + a.e * b.exyz; } /** * calculate the multiplative inverse (1/a) * under construction */ public void invert() { // under construction } /** * transform a vector * @param v a vector which is transformed by this multivector */ public void transform(sfvec3f v){ // under construction }/** * used for generation of source code * @param f filter holds read and write utilities * @param mode 0=procedure defn 1=procedure call * @param maxInstances how many instances of this class */ public void writeJava(filter f,int mode,int maxInstances){ try { // String name = generateUniqueName(); if (mode != 0) return; // no procedure defn required f.status(getClass().getName()); f.writeln("// code for "+getClass().getName(),0); f.writeln("double []d = {",2); f.writeln(""+e+",",2); f.writeln(""+ex+","+ey+","+ez+",",2); f.writeln(""+exy+","+ezx+","+eyz+",",2); f.writeln(""+exyz,2); f.writeln("};",2); } catch (Exception e1) { System.out.println("sfmulti3d.writeJava error: " + e1.toString()); } return; }/** output as a string * @param mode mode values * 0 - output modified values * 1 - output original values * 2 - output attribute * 3 - output attribute in brackets * 4 - output with f prefix * * @return a string representing this class */ public String outstring(int mode) { return "\n"+e+"\n"+ ex+","+ey+","+ez+","+"\n"+ exy+","+ezx+","+eyz+","+"\n"+ exyz; } /** write to file * @param f filter = information about output * @param mode values * 0 - output VRML97 modified values * 1 - output VRML97 original values * 2 - output xml (x3d) * 3 - output attribute in brackets * 4 - output with f prefix * @param indent indent applied to new lines */ public void write(filter f,int mode,int indent){ f.write(outstring(mode)); } /** used by mfparam.vrml2par */ public boolean instring(filter f,sfparam sfp,nodeBean n,int mode) { return false; } static public Class getEditClass(){ // return sfmulti3dEditor.class; return null; } }

metadata block
see also:

 

Correspondence about this page

Book Shop - Further reading.

Where I can, I have put links to Amazon for books that are relevant to the subject, click on the appropriate country flag to get more details of the book or to buy it from them.

flag flag flag flag flag flag Clifford Algebra to Geometric Calculus: A Unified Language for Mathematics and Physics (Fundamental Theories of Physics). This book is intended for mathematicians and physicists rather than programmers, it is very theoretical. It covers the algebra and calculus of multivectors of any dimension and is not specific to 3D modelling.

 

Terminology and Notation

Specific to this page here:

 

This site may have errors. Don't use for critical systems.

Copyright (c) 1998-2023 Martin John Baker - All rights reserved - privacy policy.