1 package com.neuronrobotics.sdk.addons.kinematics.math;
3 import java.math.BigDecimal;
4 import java.text.DecimalFormat;
5 import java.util.ArrayList;
6 import com.neuronrobotics.sdk.common.Log;
14 private ArrayList<ITransformNRChangeListener>
listeners=
null;
35 this.
setX(m.get(0, 3));
36 this.
setY(m.get(1, 3));
37 this.
setZ(m.get(2, 3));
52 public TransformNR(
double x,
double y,
double z,
double w,
double rotx,
double roty,
66 public TransformNR(
double[] cartesianSpaceVector,
double[][] rotationMatrix) {
67 this.
setX(cartesianSpaceVector[0]);
68 this.
setY(cartesianSpaceVector[1]);
69 this.
setZ(cartesianSpaceVector[2]);
79 public TransformNR(
double[] cartesianSpaceVector,
double[] quaternionVector) {
80 this.
setX(cartesianSpaceVector[0]);
81 this.
setY(cartesianSpaceVector[1]);
82 this.
setZ(cartesianSpaceVector[2]);
108 this.
setX(cartesianSpaceVector[0]);
109 this.
setY(cartesianSpaceVector[1]);
110 this.
setZ(cartesianSpaceVector[2]);
209 }
catch (Exception ex) {
210 return "Transform error" + ex.getLocalizedMessage();
223 double[][] m = matrix.getArray();
225 DecimalFormat decimalFormat =
new DecimalFormat(
"000.00");
226 int across = m.length;
227 int down = m[0].length;
229 for (
int i = 0; i < across; i++) {
231 for (
int j = 0; j < down; j++) {
233 s += decimalFormat.format(m[i][j]);
235 s += decimalFormat.format(m[i][j]);
263 double[][] transform =
new double[4][4];
267 for (
int i = 0; i < 3; i++) {
268 for (
int j = 0; j < 3; j++) {
272 for (
int i = 0; i < 3; i++) {
276 transform[0][3] =
getX();
277 transform[1][3] =
getY();
278 transform[2][3] =
getZ();
281 return new Matrix(transform);
297 double r = Math.sqrt((Math.pow(
x, 2) + Math.pow(
y, 2) + Math.pow(
z, 2)));
311 double r = Math.sqrt((Math.pow(
x, 2) + Math.pow(
y, 2) + Math.pow(
z, 2)));
346 double tilt = Math.toDegrees(
getRotation().getRotationTilt() * t);
347 double az = Math.toDegrees(
getRotation().getRotationAzimuth() * t);
348 double ele = Math.toDegrees(
getRotation().getRotationElevation() * t);
394 public TransformNR set(
double tx,
double ty,
double tz,
double[][] poseRot) {
395 if (Double.isNaN(tx))
396 throw new RuntimeException(
"Value can not be NaN");
398 if (Double.isNaN(ty))
399 throw new RuntimeException(
"Value can not be NaN");
401 if (Double.isNaN(tz))
402 throw new RuntimeException(
"Value can not be NaN");
415 if (Double.isNaN(tx))
416 throw new RuntimeException(
"Value can not be NaN");
428 if (Double.isNaN(ty))
429 throw new RuntimeException(
"Value can not be NaN");
441 if (Double.isNaN(tz))
442 throw new RuntimeException(
"Value can not be NaN");
459 "\t<x>" +
getX() +
"</x>\n" +
"\t<y>" +
getY() +
"</y>\n" +
"\t<z>" +
getZ() +
"</z>\n";
460 if (Double.isNaN(
getRotation().getRotationMatrix2QuaturnionW())
461 || Double.isNaN(
getRotation().getRotationMatrix2QuaturnionX())
462 || Double.isNaN(
getRotation().getRotationMatrix2QuaturnionY())
463 || Double.isNaN(
getRotation().getRotationMatrix2QuaturnionZ())) {
464 xml +=
"\n\t<!-- ERROR a NaN was detected and replaced with a valid rotation -->\n";
501 listeners=
new ArrayList<ITransformNRChangeListener>();
505 void fireChangeEvent() {
510 }
catch (Throwable t) {
520 e=Math.toDegrees(
getRotation().getRotationElevation());
521 }
catch(Exception ex){
522 ex.printStackTrace();
526 a=Math.toDegrees(
getRotation().getRotationAzimuth());
527 }
catch(Exception ex){
528 ex.printStackTrace();
540 }
catch(Exception ex){
541 ex.printStackTrace();
546 a=Math.toDegrees(
getRotation().getRotationAzimuth());
547 }
catch(Exception ex){
548 ex.printStackTrace();
557 }
catch(Exception ex){
558 ex.printStackTrace();
563 e=Math.toDegrees(
getRotation().getRotationElevation());
564 }
catch(Exception ex){
565 ex.printStackTrace();
double getRotationMatrix2QuaturnionZ()
double getRotationMatrix2QuaturnionY()
double getRotationMatrix2QuaturnionX()
double getRotationMatrix2QuaturnionW()
void set(double[][] poseRot)
double[][] getRotationMatrix()