-
Notifications
You must be signed in to change notification settings - Fork 58
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(utils): add utility function to move vehicle reference position (#…
…374) * feat(utils): provide utility to move vehicle position from center to front bumper * feat: happy new year 2024 * clean(utils): rename to VehicleReferenceUtils, completed set of methods
- Loading branch information
Showing
4 changed files
with
84 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
Copyright (c) 2024 Fraunhofer FOKUS and others. All rights reserved. | ||
|
||
See the NOTICE file(s) distributed with this work for additional | ||
information regarding copyright ownership. | ||
|
||
This program and the accompanying materials are made available under the | ||
terms of the Eclipse Public License 2.0 which is available at | ||
http://www.eclipse.org/legal/epl-2.0 | ||
|
||
SPDX-License-Identifier: EPL-2.0 | ||
|
||
Contact: [email protected] |
70 changes: 70 additions & 0 deletions
70
lib/mosaic-utils/src/main/java/org/eclipse/mosaic/lib/util/VehicleReferenceUtils.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
/* | ||
* Copyright (c) 2024 Fraunhofer FOKUS and others. All rights reserved. | ||
* | ||
* See the NOTICE file(s) distributed with this work for additional | ||
* information regarding copyright ownership. | ||
* | ||
* This program and the accompanying materials are made available under the | ||
* terms of the Eclipse Public License 2.0 which is available at | ||
* http://www.eclipse.org/legal/epl-2.0 | ||
* | ||
* SPDX-License-Identifier: EPL-2.0 | ||
* | ||
* Contact: [email protected] | ||
*/ | ||
|
||
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; | ||
|
||
/** | ||
* 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. | ||
*/ | ||
public static Vector3d fromCenterToFrontBumper(Vector3d pos, double heading, double length) { | ||
return VectorUtils.getDirectionVectorFromHeading(heading, new Vector3d()).multiply(length / 2).add(pos); | ||
} | ||
|
||
/** | ||
* 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(); | ||
} | ||
|
||
/** | ||
* Moves the position reference of a vehicle from its center to the center of the front bumper. | ||
*/ | ||
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); | ||
} | ||
|
||
/** | ||
* Moves the position reference of a vehicle from the center of the front bumper to its bounding box center. | ||
*/ | ||
public static CartesianPoint fromFrontBumperToCenter(CartesianPoint pos, double heading, double length) { | ||
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(); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters