-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRotation.cpp
More file actions
32 lines (24 loc) · 1002 Bytes
/
Rotation.cpp
File metadata and controls
32 lines (24 loc) · 1002 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
#include "Rotation.h"
#include <stdexcept>
#include <cmath>
void rotatePointND(const float* point, int dimensions, const float* angles, float* rotatedPoint) {
if (dimensions < 2) {
throw std::invalid_argument("Dimensions must be at least 2.");
}
// Copy the input point to the output rotatedPoint array
std::memcpy(rotatedPoint, point, dimensions * sizeof(float));
for (int i = 0; i < dimensions; ++i) {
int j = (i + 1) % dimensions; // Wrap around for the last dimension
float x = rotatedPoint[i];
float y = rotatedPoint[j];
float sina = std::sinf(angles[i]);
float cosa = std::cosf(angles[i]);
rotatedPoint[i] = x * cosa - y * sina;
rotatedPoint[j] = x * sina + y * cosa;
}
}
void rotateTesseractVertices(const float* tesseractVertices, int vertexCount, int dimensions, const float* angles, float* rotatedVertices) {
for (int i = 0; i < vertexCount; ++i) {
rotatePointND(&tesseractVertices[i * dimensions], dimensions, angles, &rotatedVertices[i * dimensions]);
}
}