diff --git a/lib/mosaic-utils/src/main/java/org/eclipse/mosaic/lib/util/VehicleUtils.java b/lib/mosaic-utils/src/main/java/org/eclipse/mosaic/lib/util/VehicleReferenceUtils.java similarity index 69% rename from lib/mosaic-utils/src/main/java/org/eclipse/mosaic/lib/util/VehicleUtils.java rename to lib/mosaic-utils/src/main/java/org/eclipse/mosaic/lib/util/VehicleReferenceUtils.java index 8d575594b..5dcd977c7 100644 --- a/lib/mosaic-utils/src/main/java/org/eclipse/mosaic/lib/util/VehicleUtils.java +++ b/lib/mosaic-utils/src/main/java/org/eclipse/mosaic/lib/util/VehicleReferenceUtils.java @@ -16,10 +16,15 @@ package org.eclipse.mosaic.lib.util; import org.eclipse.mosaic.lib.geo.CartesianPoint; +import org.eclipse.mosaic.lib.geo.GeoPoint; import org.eclipse.mosaic.lib.math.Vector3d; import org.eclipse.mosaic.lib.math.VectorUtils; -public class VehicleUtils { +/** + * Utility class collecting methods to work with vehicle positions, such + * as converting the reference point from center to front bumper and vice versa. + */ +public class VehicleReferenceUtils { /** * Moves the position reference of a vehicle from its center to the center of the front bumper. @@ -29,17 +34,23 @@ public static Vector3d fromCenterToFrontBumper(Vector3d pos, double heading, dou } /** - * Moves the position reference of a vehicle from the center of the front bumper to its bounding box center. + * Moves the position reference of a vehicle from its center to the center of the front bumper. */ - public static Vector3d fromFrontBumperToCenter(Vector3d pos, double heading, double length) { - return VectorUtils.getDirectionVectorFromHeading(heading, new Vector3d()).multiply(-length / 2).add(pos); + public static CartesianPoint fromCenterToFrontBumper(CartesianPoint pos, double heading, double length) { + return fromCenterToFrontBumper(pos.toVector3d(), heading, length).toCartesian(); } /** * Moves the position reference of a vehicle from its center to the center of the front bumper. */ - public static CartesianPoint fromCenterToFrontBumper(CartesianPoint pos, double heading, double length) { - return fromCenterToFrontBumper(pos.toVector3d(), heading, length).toCartesian(); + public static GeoPoint fromCenterToFrontBumper(GeoPoint pos, double heading, double length) { + return fromCenterToFrontBumper(pos.toVector3d(), heading, length).toGeo(); + } + /** + * Moves the position reference of a vehicle from the center of the front bumper to its bounding box center. + */ + public static Vector3d fromFrontBumperToCenter(Vector3d pos, double heading, double length) { + return VectorUtils.getDirectionVectorFromHeading(heading, new Vector3d()).multiply(-length / 2).add(pos); } /** @@ -49,4 +60,11 @@ public static CartesianPoint fromFrontBumperToCenter(CartesianPoint pos, double return fromFrontBumperToCenter(pos.toVector3d(), heading, length).toCartesian(); } + /** + * Moves the position reference of a vehicle from the center of the front bumper to its bounding box center. + */ + public static GeoPoint fromFrontBumperToCenter(GeoPoint pos, double heading, double length) { + return fromFrontBumperToCenter(pos.toVector3d(), heading, length).toGeo(); + } + }