-1

From this code I have a few issue with the sqrt, sin & cos cannot resolve method and the EPSILON cannot resolve symbol. Do I need to add in math library for the sin cos & sqrt? If yes can you give me the link to download the jar?

float omegaMagnitude = sqrt(axisX*axisX + axisY*axisY + axisZ*axisZ);

        // Normalize the rotation vector if it's big enough to get the axis
        // (that is, EPSILON should represent your maximum allowable margin of error)
        if (omegaMagnitude > EPSILON) {
            axisX /= omegaMagnitude;
            axisY /= omegaMagnitude;
            axisZ /= omegaMagnitude;
        }

        // Integrate around this axis with the angular speed by the timestep
        // in order to get a delta rotation from this sample over the timestep
        // We will convert this axis-angle representation of the delta rotation
        // into a quaternion before turning it into the rotation matrix.
        float thetaOverTwo = omegaMagnitude * dT / 2.0f;
        float sinThetaOverTwo = sin(thetaOverTwo);
        float cosThetaOverTwo = cos(thetaOverTwo);
Brian Tompsett - 汤莱恩
  • 5,753
  • 72
  • 57
  • 129
MdZain
  • 1
  • 4
  • 1
    JAR? This is Java? Those should be Math.sqrt, Math.sin and Math.cos. EPSILON should be defined as a double by you. No libraries needed. – duffymo Feb 14 '17 at 13:20
  • I suspect that the code you copied and pasted has `import static java.lang.Math.sqrt;` (and same for the other functions, and similar for the EPSILON constant). – JB Nizet Feb 14 '17 at 17:25
  • I have tried using import static java.lang.Math.sqrt; but the float omegaMagnitude = sqrt(axisX*axisX + axisY*axisY + axisZ*axisZ); is underlined in red. For the EPSILON im not really sure how to define it as double. – MdZain Feb 15 '17 at 01:38

1 Answers1

0

You don't have to download any additional libraries. Use Math.sin(x), Math.cos(x) and Math.sqrt(x) or sin(x), cos(x) and sqrt(x) and place the following code at the top of your file (but below the line package [...], if it exists):

// For Math.xxx()
import java.lang.Math;

// For xxx()
import static java.lang.Math.sin;
import static java.lang.Math.cos;
import static java.lang.Math.sqrt;

If you're using Eclipse just press Ctrl + Shift + O to automatically organize your imports (there should be similar shortcuts for other IDE's).

Marvin
  • 1,832
  • 2
  • 13
  • 22