Maths - 3d multivector Code - CPP

related classes

h file

/*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/ */__gc class sfmulti3d : public property { /// <summary> /// scalar /// </summary> public: double e; /// <summary> /// vector ex = e1,ey = e2 ,ez = e3 /// </summary> public: double ex,ey,ez; /// <summary> /// bivector exy = e1 ^ e2 ,ezx = e3 ^ e1 ,eyz = e2 ^ e3 /// </summary> public: double exy,ezx,eyz; /// <summary> /// trivector exyz = e1 ^ e2 ^ e3 /// </summary> public: double exyz;/// <summary> /// null constructor /// creates class with all zero elements /// </summary> public: sfmulti3d();/// <summary> /// copy constructor /// creates class with elements set to same value as other class /// </summary> /// <param name="other">other class to copy</param> public: sfmulti3d(sfmulti3d* other);/// <summary> /// generates an array /// </summary> /// <returns>array containing equivelant matrix</returns> public: Double toMatrix()[] ;/// <summary> /// returns a string containing the name of this type /// cant use static method below when we need to override property.vrmlType() method /// </summary> /// <returns>name of this type "sfmulti3d"</returns> public: String* vrmlType();/// <summary> /// a static method to get a string containing the name of this type /// </summary> /// <returns>name of this type "sfmulti3d"</returns> public: static String* vrmlType_s(){ return "sfmulti3d"; }/// <summary> /// override clone method /// </summary> /// <returns>clone of this class</returns> public: property* clone();/// <summary> /// add other multivector to this one /// other is not altered /// for theory see: /// https://www.euclideanspace.com/maths/algebra/clifford/arithmetic/index.htm /// </summary> /// <param name="other">the multivector to be added to this, other is not altered</param> public: void add(sfmulti3d* other);/// <summary> /// subtract other multivector from this one /// other is not altered /// for theory see: /// https://www.euclideanspace.com/maths/algebra/clifford/arithmetic/index.htm /// </summary> /// <param name="other">the multivector to be subtracted from this, other is not altered</param> public: void sub(sfmulti3d* other);/// <summary> /// multiply another multivector with this one /// other is not altered /// for theory see: /// https://www.euclideanspace.com/maths/algebra/clifford/arithmetic/index.htm /// </summary> /// <param name="other">the multivector to be multiplied by this, other is not altered</param> public: void mult(sfmulti3d* other);/// <summary> /// 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 /// </summary> /// <param name="a">the first multivector to be multiplied, it is not altered</param> /// <param name="b">the second multivector to be multiplied, it is not altered</param> public: void mult(sfmulti3d* a,sfmulti3d* b);/// <summary> /// calculate the multiplative inverse (1/a) /// under construction /// </summary> public: void invert();/// <summary> /// transform a vector /// </summary> /// <param name="v">a vector which is transformed by this multivector</param> public: void transform(sfvec3f* v);/// <summary> /// used for generation of source code /// </summary> /// <param name="f">filter holds read and write utilities</param> /// <param name="mode">0=procedure defn 1=procedure call</param> /// <param name="maxInstances">how many instances of this class</param> public: void writeJava(filter* f,int mode,int maxInstances);/// <summary> /// output as a string /// </summary> /// <param name="mode">mode mode values /// 0 - output modified values /// 1 - output original values /// 2 - output attribute /// 3 - output attribute in brackets /// 4 - output with f prefix</param> /// <returns>string representing this class</returns> public: String* outstring(int mode);/// <summary> /// write to file /// </summary> /// <param name="f">filter = information about output</param> /// <param name="mode">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> /// <param name="indent">indent indent applied to new lines</param> public: void write(filter* f,int mode,int indent);/// <summary> /// used by mfparam.vrml2par /// </summary> /// <param name="f"></param> /// <param name="sfp"></param> /// <param name="n"></param> /// <param name="mode"></param> /// <returns></returns> public: bool instring(filter* f,sfparam* sfp,nodeBean* n,int mode);/// <summary> /// get a class that can edit this /// </summary> /// <returns></returns> public: static Type* getEditClass(){ //return typeof(sfmulti3dEditor); return 0; } };

CPP file

/*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 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 License for more details.For information about the GNU General 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/ */#include "mjbModel.h"/// <summary> /// null constructor /// creates class with all zero elements /// </summary> sfmulti3d::sfmulti3d() { }/// <summary> /// copy constructor /// creates class with elements set to same value as other class /// </summary> /// <param name="other">other class to copy</param> sfmulti3d::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; }/// <summary> /// generates an array /// </summary> /// <returns>array containing equivelant matrix</returns> Double sfmulti3d::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) { Console::WriteLine("sfmulti3d.instring {0}",e1); } return matrix; }/// <summary> /// returns a string containing the name of this type /// cant use static method below when we need to override property.vrmlType() method /// </summary> /// <returns>name of this type "sfmulti3d"</returns> String* sfmulti3d::vrmlType(){ return "sfmulti3d"; } /// <summary> /// override clone method /// </summary> /// <returns>clone of this class</returns> property* sfmulti3d::clone() { return new sfmulti3d(this); }/// <summary> /// add other multivector to this one /// other is not altered /// for theory see: /// https://www.euclideanspace.com/maths/algebra/clifford/arithmetic/index.htm /// </summary> /// <param name="other">the multivector to be added to this, other is not altered</param> void sfmulti3d::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; }/// <summary> /// subtract other multivector from this one /// other is not altered /// for theory see: /// https://www.euclideanspace.com/maths/algebra/clifford/arithmetic/index.htm /// </summary> /// <param name="other">the multivector to be subtracted from this, other is not altered</param> void sfmulti3d::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; }/// <summary> /// multiply another multivector with this one /// other is not altered /// for theory see: /// https://www.euclideanspace.com/maths/algebra/clifford/arithmetic/index.htm /// </summary> /// <param name="other">the multivector to be multiplied by this, other is not altered</param> void sfmulti3d::mult(sfmulti3d* other) { sfmulti3d* tmp = new sfmulti3d(this); mult(tmp,other); }/// <summary> /// 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 /// </summary> /// <param name="a">the first multivector to be multiplied, it is not altered</param> /// <param name="b">the second multivector to be multiplied, it is not altered</param> void sfmulti3d::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; }/// <summary> /// calculate the multiplative inverse (1/a) /// under construction /// </summary> void sfmulti3d::invert() { // under construction }/// <summary> /// transform a vector /// </summary> /// <param name="v">a vector which is transformed by this multivector</param> void sfmulti3d::transform(sfvec3f* v){ // under construction }/// <summary> /// used for generation of source code /// </summary> /// <param name="f">filter holds read and write utilities</param> /// <param name="mode">0=procedure defn 1=procedure call</param> /// <param name="maxInstances">how many instances of this class</param> void sfmulti3d::writeJava(filter* f,int mode,int maxInstances){ try { // String name = generateUniqueName(); if (mode != 0) return; // no procedure defn required f->status(GetType()->Name); f->writeln(String::Concat("// code for ",GetType()->Name),0); f->writeln("double []d = {",2); f->writeln(String::Concat(__box(e),S","),2); f->writeln(String::Concat(__box(ex),S",",__box(ey),S",",__box(ez),S","),2); f->writeln(String::Concat(__box(exy),S",",__box(ezx),S",",__box(eyz),S","),2); f->writeln(String::Concat(__box(exyz),S""),2); f->writeln("};",2); } catch (Exception* e1) { Console::WriteLine("sfmulti3d.writeJava {0}",e1); } return; }/// <summary> /// output as a string /// </summary> /// <param name="mode">mode mode values /// 0 - output modified values /// 1 - output original values /// 2 - output attribute /// 3 - output attribute in brackets /// 4 - output with f prefix</param> /// <returns>string representing this class</returns> String* sfmulti3d::outstring(int mode) { return String::Concat(S"\n",__box(e),S"\n", __box(ex),S",",__box(ey),S",",__box(ez),S",",S"\n", __box(exy),S",",__box(ezx),S",",__box(eyz),S",",S"\n", __box(exyz)); }/// <summary> /// write to file /// </summary> /// <param name="f">filter = information about output</param> /// <param name="mode">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> /// <param name="indent">indent indent applied to new lines</param> void sfmulti3d::write(filter* f,int mode,int indent){ f->write(outstring(mode)); }/// <summary> /// used by mfparam.vrml2par /// </summary> /// <param name="f"></param> /// <param name="sfp"></param> /// <param name="n"></param> /// <param name="mode"></param> /// <returns></returns> bool sfmulti3d::instring(filter* f,sfparam* sfp,nodeBean* n,int mode) { return false; }

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.