1 package com.neuronrobotics.sdk.addons.kinematics.math;
 
    5 import org.apache.commons.math3.geometry.euclidean.threed.CardanEulerSingularityException;
 
    6 import org.apache.commons.math3.geometry.euclidean.threed.Rotation;
 
    7 import org.apache.commons.math3.geometry.euclidean.threed.RotationConvention;
 
    8 import org.apache.commons.math3.geometry.euclidean.threed.RotationOrder;
 
   10 import com.neuronrobotics.sdk.common.Log;
 
   25     private Rotation 
storage = 
new Rotation(1, 0, 0, 0, 
false);
 
   26     private static RotationOrder 
order = RotationOrder.ZYX;
 
   27     private static RotationConvention 
convention = RotationConvention.VECTOR_OPERATOR;
 
   59     public RotationNR(
double tilt, 
double azumeth, 
double elevation) {
 
   60         if (Double.isNaN(tilt))
 
   61             throw new RuntimeException(
"Value can not be NaN");
 
   62         if (Double.isNaN(azumeth))
 
   63             throw new RuntimeException(
"Value can not be NaN");
 
   64         if (Double.isNaN(elevation))
 
   65             throw new RuntimeException(
"Value can not be NaN");
 
   66         if (elevation > 90 || elevation < -90) {
 
   67             throw new RuntimeException(
"Elevation can not be greater than 90 nor less than -90");
 
   72             Log.
error(
"Failing to set proper angle, jittering");
 
   73             loadFromAngles(tilt + Math.random() * .02 + .001, azumeth + Math.random() * .02 + .001,
 
   74                     elevation + Math.random() * .02 + .001);
 
   96         this(values[0], values[1], values[2], values[3]);
 
  107         double[][] rotation = 
new double[3][3];
 
  108         double rotationAngleRadians = Math.PI / 180 * rotationAngleDegrees;
 
  116         rotation[1][1] = Math.cos(rotationAngleRadians);
 
  117         rotation[2][1] = Math.sin(rotationAngleRadians);
 
  120         rotation[1][2] = -Math.sin(rotationAngleRadians);
 
  121         rotation[2][2] = Math.cos(rotationAngleRadians);
 
  134         double[][] rotation = 
new double[3][3];
 
  135         double rotationAngleRadians = Math.PI / 180 * rotationAngleDegrees;
 
  138         rotation[0][0] = Math.cos(rotationAngleRadians);
 
  140         rotation[2][0] = -Math.sin(rotationAngleRadians);
 
  146         rotation[0][2] = Math.sin(rotationAngleRadians);
 
  148         rotation[2][2] = Math.cos(rotationAngleRadians);
 
  161         double[][] rotation = 
new double[3][3];
 
  162         double rotationAngleRadians = Math.PI / 180 * rotationAngleDegrees;
 
  165         rotation[0][0] = Math.cos(rotationAngleRadians);
 
  166         rotation[1][0] = Math.sin(rotationAngleRadians);
 
  169         rotation[0][1] = -Math.sin(rotationAngleRadians);
 
  170         rotation[1][1] = Math.cos(rotationAngleRadians);
 
  204         double[][] rotation = 
new double[3][3];
 
  205         for (
int i = 0; i < 3; i++) {
 
  206             for (
int j = 0; j < 3; j++) {
 
  207                 rotation[i][j] = m.get(i, j);
 
  220         if (rotM.length != 3)
 
  221             throw new RuntimeException(
"Must be 3x3 rotation matrix");
 
  222         for (
int i = 0; i < 3; i++) {
 
  223             if (rotM[i].length != 3) {
 
  224                 throw new RuntimeException(
"Must be 3x3 rotation matrix");
 
  250                 + 
"Rotation angle (degrees): " + 
"az= " + Math.toDegrees(
getRotationAzimuth()) + 
", elev= " 
  252         }
catch(Exception ex){
 
  253             return "Rotation error"+ex.getLocalizedMessage();
 
  268         for (
int i = 0; i < 3; i++) {
 
  270             for (
int j = 0; j < 3; j++) {
 
  271                 s += array[i][j] + 
"\t\t";
 
  276         return "Matrix = " + s;
 
  293             throw new RuntimeException(
"Value can not be NaN");
 
  295             throw new RuntimeException(
"Value can not be NaN");
 
  297             throw new RuntimeException(
"Value can not be NaN");
 
  299             throw new RuntimeException(
"Value can not be NaN");
 
  300         setStorage(
new Rotation(w,- x, -y, -z, 
true));
 
  314     public static boolean bound(
double low, 
double high, 
double n) {
 
  315         return n >= low && n <= high;
 
  320                 Math.toRadians(tilt)));
 
  351         double epsilon=1.0E-7;
 
  352         if(Math.abs(angles[0] - Math.toRadians(180)) < epsilon&&
 
  353            Math.abs(angles[2] - Math.toRadians(180)) < epsilon  ){
 
  360     private double eulerFix(
double offsetSize, 
int index){
 
  361         double offset = (index==1?offsetSize:0);
 
  366         double finalResult= angles[index];
 
  367         return finalResult+offset;
 
  373         } 
catch (CardanEulerSingularityException e) {
 
  375                 return eulerFix( Math.toRadians(5),  index);
 
  376             } 
catch (CardanEulerSingularityException ex) {
 
  377                 return eulerFix(  Math.toRadians(-5),  index);
 
  444     public void set(
double[][] poseRot) {
 
double getRotationElevation()
void simpilfyAngles(double[] angles)
double getRotationAzimuth()
void loadRotations(double[][] rotM)
double getRotationMatrix2QuaturnionZ()
double getRotationMatrix2QuaturnionY()
static RotationConvention convention
RotationNR(double[] values)
double eulerFix(double offsetSize, int index)
double getAngle(int index)
RotationNR(double[][] rotationMatrix)
void loadFromAngles(double tilt, double azumeth, double elevation)
RotationNR(Rotation store)
static RotationNR getRotationY(double rotationAngleDegrees)
static RotationOrder order
RotationNR(double w, double x, double y, double z)
void quaternion2RotationMatrix(double w, double x, double y, double z)
RotationNR(double tilt, double azumeth, double elevation)
double getRotationMatrix2QuaturnionX()
static void setConvention(RotationConvention convention)
static boolean bound(double low, double high, double n)
static RotationNR getRotationZ(double rotationAngleDegrees)
double getRotationMatrix2QuaturnionW()
static void setOrder(RotationOrder o)
void setStorage(Rotation storage)
String toString(double[][] array)
static RotationOrder getOrder()
static RotationNR getRotationX(double rotationAngleDegrees)
static RotationConvention getConvention()
double[][] getRotationMatrix()
static void error(String message)