C
C#3y ago
Topend

Rotational matrix transformation

Yeh look i've got a point, and it's got an offset for both X, and Y. From These offsets we have a rotation(float) and we need to calculate the new center. My code is absolute garbage and i've got things close, but they're not close enough for pathfinder, and i'd like to actually understand whats going on a little bit more, if someone knows some more resources that relate to this? i've mainly arrived here by trial and error.(i know this is not c#) but this is more a conceptual question.
8 Replies
Doombox
Doombox3y ago
maths is not my strong suit so you'll have to bear with me a bit, but first you need to know the coordinates of the centre point and the point you want to rotate in the same co-ordinate system so you need those points to be both in world space or local space, whatever that means in your application
static (double newX, double newY) RotatePoint(
double rotateX, double rotateY,
double centerX, double centerY,
double angleInDegrees)
{
var angleInRadians = angleInDegrees * (Math.PI / 180);
var cosTheta = Math.Cos(angleInRadians);
var sinTheta = Math.Sin(angleInRadians);
return (cosTheta * (rotateX - centerX) - sinTheta * (rotateY - centerY) + centerX,
sinTheta * (rotateX - centerX) + cosTheta * (rotateY - centerY) + centerX);
}
static (double newX, double newY) RotatePoint(
double rotateX, double rotateY,
double centerX, double centerY,
double angleInDegrees)
{
var angleInRadians = angleInDegrees * (Math.PI / 180);
var cosTheta = Math.Cos(angleInRadians);
var sinTheta = Math.Sin(angleInRadians);
return (cosTheta * (rotateX - centerX) - sinTheta * (rotateY - centerY) + centerX,
sinTheta * (rotateX - centerX) + cosTheta * (rotateY - centerY) + centerX);
}
then you can use something like this
Doombox
Doombox3y ago
think my coordinates system might be messed up but it works
Doombox
Doombox3y ago
I hate maths, my head is already spinning
Xymanek
Xymanek3y ago
by how many degrees trollnek
Doombox
Doombox3y ago
<a:gpa_pepe_spinhmm:985633122240573472> it never ends just spent the last few hours wrestling with github's garbage CI, then I decided to help someone with a maths question for no particularly good reason
Topend
TopendOP3y ago
sorry it was 1am when i posted the question i will have feedback after work today!! cant be late for work -.-
Topend
TopendOP3y ago
i love cat(mull-rom splines)
you could also use Matrix4x4 with all its transformation functions to create a transformation matrix and multiply your vector with it it'll be a lot less work
Want results from more Discord servers?
Add your server