Aufgrund von Umarbeiten des s3 Storage wird es in GitLab, in nächster Zeit, mögliche Performance-Einbußen geben. Näheres dazu unter: https://maintenance.itc.rwth-aachen.de/ticket/status/messages/43/show_ticket/6670

Commit 3bef5132 authored by Jean Meurice's avatar Jean Meurice

In Place Math, New Data Types

parent b85edd3e
Pipeline #284369 passed with stage
in 48 seconds
/**
* (c) https://github.com/MontiCore/monticore
*
* The license generally applicable for this project
* can be found under https://github.com/MontiCore/monticore.
*/
package de.rwth.montisim.commons.boundingbox;
import de.rwth.montisim.commons.utils.Vec3;
public class Collision {
public Vec3 rel_pos = new Vec3();
public Vec3 normal = new Vec3();
public double penetration = 0;
}
\ No newline at end of file
......@@ -10,15 +10,7 @@ import de.rwth.montisim.commons.utils.Mat3;
import de.rwth.montisim.commons.utils.Vec3;
public class OBB implements BoundingBox {
public Vec3 position;
public Vec3 halfSize;
//Every collumn is a unit axis in the rotated space
public Mat3 rotation;
/// Takes ownership of the position and rotation
public OBB(Vec3 position, Vec3 size, Mat3 rotation) {
this.halfSize = size.multiply(0.5);
this.position = position;
this.rotation = rotation;
}
public Vec3 offset = new Vec3(); // Offset from center of mass
public Vec3 half_extent = new Vec3();
public Mat3 axes = new Mat3();
}
\ No newline at end of file
......@@ -7,10 +7,26 @@
package de.rwth.montisim.commons.dynamicinterface;
public class DataType {
public static final DataType DOUBLE = new DataType(Type.DOUBLE);
public static final DataType FLOAT = new DataType(Type.FLOAT);
public static final DataType INT = new DataType(Type.INT);
public static final DataType BOOLEAN = new DataType(Type.BOOLEAN);
public static final DataType BYTE = new DataType(Type.BYTE);
public static final DataType EMPTY = new DataType(Type.EMPTY);
public static final DataType VEC2 = new DataType(Type.VEC2);
public static final DataType VEC3 = new DataType(Type.VEC3);
public static enum Type {
DOUBLE,
FLOAT,
INT,
BYTE,
BOOLEAN,
EMPTY,
VEC2,
VEC3,
STRUCT,
ARRAY
}
......@@ -21,6 +37,11 @@ public class DataType {
case DOUBLE: return "double";
case FLOAT: return "float";
case INT: return "int";
case BYTE: return "byte";
case BOOLEAN: return "bool";
case EMPTY: return "void";
case VEC2: return "Vec2";
case VEC3: return "Vec3";
case STRUCT: return "struct";
case ARRAY: return "array";
default: return "UNKNOWN_TYPE";
......@@ -32,6 +53,11 @@ public class DataType {
case DOUBLE: return 8;
case FLOAT: return 4;
case INT: return 4;
case BYTE: return 1;
case BOOLEAN: return 1;
case EMPTY: return 0;
case VEC2: return 16;
case VEC3: return 24;
default:
return -1; //Should not occur
}
......@@ -52,19 +78,6 @@ public class DataType {
this.type = type;
this.dataSize = dataSize;
}
public static DataType newDoubleType(){
return new DataType(Type.DOUBLE);
}
public static DataType newFloatType(){
return new DataType(Type.FLOAT);
}
public static DataType newIntType(){
return new DataType(Type.INT);
}
......
......@@ -14,7 +14,8 @@ import org.apache.commons.math3.linear.RealVector;
public final class Geometry {
public static final double DEG_TO_RAD = 2.0 * Math.PI / 360.0;
public static final double RAD_TO_DEG = 1 / DEG_TO_RAD;
public static final float INCH = 0.0254f;
public static final double INCH_TO_METERS = 0.0254;
public static final double FOOT_TO_METERS = 0.3048;
public static Mat3 rotationAroundX(double angle) {
return new Mat3(new Vec3(1, 0, 0), new Vec3(0, Math.cos(angle), Math.sin(angle)),
......
......@@ -5,7 +5,7 @@
* can be found under https://github.com/MontiCore/monticore.
*/
package de.rwth.montisim.commons.utils;
// TODO add all missing variants & Vec2 variants & Vec4
/**
* "In Place Math": in-memory vector and matrix operations. (Does not create new Vec/Mat objects)
*/
......@@ -21,12 +21,22 @@ public class IPM {
target.y = a.y + b.y;
target.z = a.z + b.z;
}
/** target = a + b */
public static void addToVec(Vec2 a, Vec2 b, Vec2 target){
target.x = a.x + b.x;
target.y = a.y + b.y;
}
/** a += b */
public static void add(Vec3 a, Vec3 b) {
a.x += b.x;
a.y += b.y;
a.z += b.z;
}
/** a += b */
public static void add(Vec2 a, Vec2 b) {
a.x += b.x;
a.y += b.y;
}
/** target = a - b */
......@@ -35,12 +45,22 @@ public class IPM {
target.y = a.y - b.y;
target.z = a.z - b.z;
}
/** target = a - b */
public static void subtractToVec(Vec2 a, Vec2 b, Vec2 target){
target.x = a.x - b.x;
target.y = a.y - b.y;
}
/** a -= b */
public static void subtract(Vec3 a, Vec3 b) {
a.x -= b.x;
a.y -= b.y;
a.z -= b.z;
}
/** a -= b */
public static void subtract(Vec2 a, Vec2 b) {
a.x -= b.x;
a.y -= b.y;
}
/** target = a * s */
......@@ -49,12 +69,22 @@ public class IPM {
target.y = a.y * s;
target.z = a.z * s;
}
/** target = a * s */
public static void multiplyToVec(Vec2 a, double s, Vec2 target) {
target.x = a.x * s;
target.y = a.y * s;
}
/** a *= s */
public static void multiply(Vec3 a, double s) {
a.x *= s;
a.y *= s;
a.z *= s;
}
/** a *= s */
public static void multiply(Vec2 a, double s) {
a.x *= s;
a.y *= s;
}
/** a = a/|a| */
public static void normalize(Vec3 a) {
......@@ -66,6 +96,16 @@ public class IPM {
a.x = 0; a.y = 0; a.z = 0;
}
}
/** a = a/|a| */
public static void normalize(Vec2 a) {
double length = a.magnitude();
double i = 1 / length;
if (length > 0.000001){
a.x *= i; a.y *= i;
} else {
a.x = 0; a.y = 0;
}
}
/** target = a/|a| */
public static void normalizeToVec(Vec3 a, Vec3 target) {
double length = a.magnitude();
......@@ -78,6 +118,17 @@ public class IPM {
target.x = 0; target.y = 0; target.z = 0;
}
}
/** target = a/|a| */
public static void normalizeToVec(Vec2 a, Vec2 target) {
double length = a.magnitude();
double i = 1 / length;
if (length > 0.000001){
target.x = a.x * i;
target.y = a.y * i;
} else {
target.x = 0; target.y = 0;
}
}
/** target = a x b */
......@@ -102,6 +153,10 @@ public class IPM {
public static double dot(Vec3 a, Vec3 b) {
return a.x * b.x + a.y * b.y + a.z * b.z;
}
/** Dot product */
public static double dot(Vec2 a, Vec2 b) {
return a.x * b.x + a.y * b.y;
}
/** a = midpoint(a, b) */
......@@ -110,12 +165,22 @@ public class IPM {
a.y = (b.y + a.y) * 0.5;
a.z = (b.z + a.z) * 0.5;
}
/** a = midpoint(a, b) */
public static void midpoint(Vec2 a, Vec2 b) {
a.x = (b.x + a.x) * 0.5;
a.y = (b.y + a.y) * 0.5;
}
/** target = midpoint(a, b) */
public static void midpointToVec(Vec3 a, Vec3 b, Vec3 target) {
target.x = (b.x + a.x) * 0.5;
target.y = (b.y + a.y) * 0.5;
target.z = (b.z + a.z) * 0.5;
}
/** target = midpoint(a, b) */
public static void midpointToVec(Vec2 a, Vec2 b, Vec2 target) {
target.x = (b.x + a.x) * 0.5;
target.y = (b.y + a.y) * 0.5;
}
/*
MATRIX FUNCTIONS
......
......@@ -34,11 +34,23 @@ public class SimpleCoordinateConverter {
inv_lon_factor = 1 / lon_factor;
}
public Vec2 coordsToMeters(Coordinates coords){
return new Vec2( (coords.lon-ref.lon) *lon_factor, (coords.lat-ref.lat) * DEG_TO_METERS);
public void coordsToMeters(Coordinates coords, Vec2 target){
target.x = (coords.lon-ref.lon) *lon_factor;
target.y = (coords.lat-ref.lat) * DEG_TO_METERS;
}
public Coordinates metersToCoords(Vec2 meters){
return new Coordinates(meters.x*inv_lon_factor + ref.lon, meters.y*METERS_TO_DEG + ref.lat);
public void coordsToMeters(Coordinates coords, Vec3 target){
target.x = (coords.lon-ref.lon) *lon_factor;
target.y = (coords.lat-ref.lat) * DEG_TO_METERS;
}
public void metersToCoords(Vec2 meters, Coordinates target){
target.lon = meters.x*inv_lon_factor + ref.lon;
target.lat = meters.y*METERS_TO_DEG + ref.lat;
}
public void metersToCoords(Vec3 meters, Coordinates target){
target.lon = meters.x*inv_lon_factor + ref.lon;
target.lat = meters.y*METERS_TO_DEG + ref.lat;
}
}
\ No newline at end of file
......@@ -19,6 +19,11 @@ public class Vec2 {
this.y = y;
}
public Vec2(Vec3 v) {
this.x = v.x;
this.y = v.y;
}
/// Creates a vector where all entries are 'a'
public Vec2(double a) {
this.x = a;
......@@ -30,6 +35,20 @@ public class Vec2 {
this(0);
}
public void set(double x, double y) {
this.x = x;
this.y = y;
}
public void set(Vec2 v){
this.x = v.x;
this.y = v.y;
}
public void set(Vec3 v){
this.x = v.x;
this.y = v.y;
}
/// Returns a NEW Vec2 with the result
public Vec2 add(double x, double y) {
return new Vec2(x + this.x, y + this.y);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment