Giter Site home page Giter Site logo

quaternion's People

Contributors

julianmateu avatar

Watchers

 avatar  avatar

quaternion's Issues

Error with tolerance in test.

@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.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.