Rotating a point around (0,0)

Blitz3D Forums/Blitz3D Programming/Rotating a point around (0,0)

Ross C(Posted 2003) [#1]
Hey, how would i go about rotating a point around the centre point (0,0). Say i have a point (3,3), and i want to rotate it by 45 deg, how would i go about it. I'm having somewhat of a mental block :S


podperson(Posted 2003) [#2]
In 2D?

x1 = x0 * cos(a) - y0 * sin(a)
y1 = y0 * cos(a) + x0 * sin(a)

In 3D using Blitz3D you can simply:

(a) Create a pivot
(b) Create a second pivot child to the first with coords 3,3,0
(c) Rotate the first pivot
(d) Read the coordinates on the second pivot


Stevie G(Posted 2003) [#3]
Ross - This should work.

x# = 3 : y# = 3 : angle# = 45

new_x# = x * cos(angle) - y * sin(angle)
new_y# = y * cos(angle) + x * sin(angle)


jfk EO-11110(Posted 2003) [#4]
Something like this:
lets assume P is a Point and also a Pivot Entity
rot_centerx#=0
rot_centerz#=0
dist_x#=entityx(p)-rot_centerx#
dist_z#=entityz(p)-rot_centerz#

cura#=atan2(dist_x#,dist_z#)
dist#=sqr((dist_x*dist_x)+(dist_z*dist_z))
newa#=(cura#+45) mod 360
positionentity p,rot_centerx+sin(newa)*dist,entityy(p),rot_centerz+cos(newa)*dist


If P is only a Coordinate, then use the Coordinate Values instead of those EntityX() etc. Commands.

BTW: maybe I confused Sin and Cos - in that case just swap them.


Ross C(Posted 2003) [#5]
It's for 3d rotation of quads. Thanks for you help both of you'z :)