julianmateu / quaternion Goto Github PK
View Code? Open in Web Editor NEWJava Class to operate with Quaternions
Home Page: https://julianmateu.github.io/Quaternion/
Java Class to operate with Quaternions
Home Page: https://julianmateu.github.io/Quaternion/
@basicNew, I have a failure in one of the tests, here is the message:
There was 1 failure:
1) testMultiplicationQuaternion(TestQuaternion)junit.framework.AssertionFailedError: expected:<( 1.0714285714285714 ; 0.0 ; 0.0 ; 2.7755575615628914E-17 )> but was:<( 1.0 ; 0.0 ; 0.0 ; 0.0 )>
at TestQuaternion.testMultiplicationQuaternion(TestQuaternion.java:156)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
FAILURES!!!
Tests run: 5, Failures: 1, Errors: 0
I suspect it is a tolerance issue. I can't define a tolerance for assertEquals()
because it should be a double (there is no assertEquals(Object,Object,Object)
, instead there is an assertEquals(Object,Object,Object)
). I could define an assertEquals
that subtracts the two objects an checks its difference is smaller than the tolerance, but the first number I get should be 1 and is 1.07. This seems a very big numerical error.
Here is the code of the method:
/**
* Method to multiply two Quaternions and find their Hamilton product.
*
* @return Returns a new Quaternion with the result of the Hamilton product.
*/
public Quaternion multiply(Quaternion factor) {
return new Quaternion(
this.r * factor.getR() - this.i * factor.getI()
- this.j * factor.getJ() - this.k * factor.getK(),
this.r * factor.getI() + this.i * factor.getR()
+ this.j * factor.getK() - this.k * factor.getJ(),
this.r * factor.getJ() - this.i * factor.getK()
+ this.j * factor.getR() + this.k * factor.getI(),
this.r * factor.getK() + this.i * factor.getJ()
- this.j * factor.getI() + this.k * factor.getR());
}
And here the code of the test:
assertEquals(new Quaternion(1, 2, 3, 4).multiply(new Quaternion(
((double)1.0)/28, ((double)-2.0)/28, ((double)-3.0)/28, ((double)-4.0)/28)),
new Quaternion(1, 0, 0, 0)); // Multiplying by right inverse.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.