-
-
Notifications
You must be signed in to change notification settings - Fork 109
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'develop' of github.com-myrobotlab:MyRobotLab/myrobotlab…
… into inmoov-and-statemachine-1
- Loading branch information
Showing
4 changed files
with
82 additions
and
22 deletions.
There are no files selected for viewing
Submodule depthai
added at
65fc1c
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,45 @@ | ||
import java.util.Vector; | ||
|
||
public class VectorAngleCalculator { | ||
public static double calculateAngle(Vector<Double> vector1, Vector<Double> vector2) { | ||
// Check if the vectors have the same dimension | ||
if (vector1.size() != vector2.size()) { | ||
throw new IllegalArgumentException("Vectors must have the same dimension"); | ||
} | ||
|
||
// Calculate the dot product of the vectors | ||
double dotProduct = 0.0; | ||
double magnitude1 = 0.0; | ||
double magnitude2 = 0.0; | ||
|
||
for (int i = 0; i < vector1.size(); i++) { | ||
dotProduct += vector1.get(i) * vector2.get(i); | ||
magnitude1 += Math.pow(vector1.get(i), 2); | ||
magnitude2 += Math.pow(vector2.get(i), 2); | ||
} | ||
|
||
magnitude1 = Math.sqrt(magnitude1); | ||
magnitude2 = Math.sqrt(magnitude2); | ||
|
||
// Calculate the angle in radians | ||
double radians = Math.acos(dotProduct / (magnitude1 * magnitude2)); | ||
|
||
// Convert radians to degrees | ||
double degrees = Math.toDegrees(radians); | ||
|
||
return degrees; | ||
} | ||
|
||
public static void main(String[] args) { | ||
Vector<Double> vector1 = new Vector<>(); | ||
vector1.add(1.0); | ||
vector1.add(0.0); | ||
|
||
Vector<Double> vector2 = new Vector<>(); | ||
vector2.add(1.0); | ||
vector2.add(1.0); | ||
|
||
double angleDegrees = calculateAngle(vector1, vector2); | ||
System.out.println("Angle between vectors: " + angleDegrees + " degrees"); | ||
} | ||
} |
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