RLPark 1.0.0
Reinforcement Learning Framework in Java
|
00001 package rlpark.plugin.rltoys.problems.helicopter; 00002 00003 import zephyr.plugin.core.api.monitoring.annotations.Monitor; 00004 00005 @Monitor 00006 public class HeliVector { 00007 public double x; 00008 public double y; 00009 public double z; 00010 00011 public HeliVector(HeliVector vecToCopy) { 00012 this.x = vecToCopy.x; 00013 this.y = vecToCopy.y; 00014 this.z = vecToCopy.z; 00015 } 00016 00017 public HeliVector(double x, double y, double z) { 00018 this.x = x; 00019 this.y = y; 00020 this.z = z; 00021 } 00022 00023 public Quaternion to_quaternion() { 00024 Quaternion quat; 00025 double rotation_angle = Math.sqrt(x * x + y * y + z * z); 00026 if (rotation_angle < 1e-4) { // avoid division by zero -- also: can use 00027 // simpler computation in this case, since for 00028 // small angles sin(x) = x is a good 00029 // approximation 00030 quat = new Quaternion(x / 2.0f, y / 2.0f, z / 2.0f, 0.0f); 00031 quat.w = Math.sqrt(1.0f - (quat.x * quat.x + quat.y * quat.y + quat.z * quat.z)); 00032 } else { 00033 quat = new Quaternion(Math.sin(rotation_angle / 2.0f) * (x / rotation_angle), Math.sin(rotation_angle / 2.0f) 00034 * (y / rotation_angle), Math.sin(rotation_angle / 2.0f) * (z / rotation_angle), 00035 Math.cos(rotation_angle / 2.0f)); 00036 } 00037 return quat; 00038 } 00039 00040 public HeliVector rotate(Quaternion q) { 00041 return q.mult(new Quaternion(this)).mult(q.conj()).complex_part(); 00042 } 00043 00044 public HeliVector express_in_quat_frame(Quaternion q) { 00045 return this.rotate(q.conj()); 00046 } 00047 00048 public void reset() { 00049 x = 0.0; 00050 y = 0.0; 00051 z = 0.0; 00052 } 00053 }