Hi, Im looking for an algorithm that can rotate a pixel, ie move a pixel from x,y to newx,newy based on a given angle(most likely not 0,90,180,270,360) I have seen it somewhere i just cant remember the math behind it.
surely you mean trigonometry?
or around a given origin (centre point)
Note that this is untested and from memory of math from school over 14 years ago so it may be incorrect
Or like this:
To rotate a point ‘p’ around another point/origin ‘c’ simply subtract c from p, then rotate p and add c.
p.x -= c.x
p.y -= c.y
newx = p.x * cos(angle) - p.y * sin(angle)
newy = p.x * sin(angle) + p.y * cos(angle)
p.x = newx + c.x
p.y = newy + c.y
Exactly what i was looking for thanks! this will really help me with my 3d engine.
How would I apply this to three d? Say I have point xyz wanting to rotated around point pxpypz?
Exactly the same principle; you just rotate around an axis of your choosing, rather than a point.
But I’d rather you use matrices:
Here is an example of a rotation matrix. It can be used to rotate a vector around any arbitary axis.
Keep things simple. A rotation is one way to describe how one choice of a coordinate frame is related to some other. In the case of a rotation and matrices, then the matrix describes how the orthonormal basis (the X,Y & Z axis directions) change…which is a parallel projection…so in the 3D, 3x3 matrix form each row (or column depending on choice of convention) is ‘dotted’ with the input to project from one to the other. So each source direction is dotted with the target direction (you so have 3 equations) to get the output. Humm…that was probably as clear as mud.