Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Rotating a point
#11
[syntax="QBasic"]
IF x=1 THEN PRINT "holy cow."
[/syntax]

[/syntax] and [syntax="QBasic"] (other way round obviously, I did this so it didn't highlight it)
Reply
#12
heres an email response i sent to someone who asked me basically the same question:::

Quote:for rotation on a 2d plane, take a normal x/y axis and place a point on the x axis somewhere

a simple exercise would be to rotate that point by 90 degrees up to the y axis

so point [10,0] becomes [0,10]

well, cos(0degrees) = 1 and sin(90 degrees) = 1

so if you want the x value to be at 10 on the x axis at 0 degrees then multiply the x value by cos(angle), this will give you the rotated x coordinate

now, since you want that initial point on the x axis to be put up to the top of the y axis, you'll multiply the x point times sin(90) so that at 90 degrees the rotated y value will be 10 units high

so far you have

rotatedx = x * cos(angle)
rotatedy = x * sin(angle)

so that if you put in the coordinate [10,0] it will be on the x plane at value 10 at 0 degrees and it will be on the y plane at 90 degrees...

now, say you want the point [10,2] the be rotated 90 degrees, well, at 0 degrees y ou want the point to be 2 units above the x axis

so you add to your rotatedy value y * cos(0) because at 0 degrees cos(0) = 1 and sin(0) = 0... so that your x*sin[0] = 0 and y*cos[0] = 2, now your rotatedy formula will acurately rotate this point that is not exactly on the x axis

next is to fix the rotatedx formula so that at 90 degrees the original [10,2] is rotated to [-2,10] in order to do this your rotated x value needs to end up at -2 at 90 degrees, well, cos[90] = 0 so you need to use sin[90] and multiply it by the negative of the original y value

so you end up with

rotatedx = x * cos[angle] - y * sin[angle]
rotatedy = x * sin[angle] + y * cos[angle]

this will allow rotation on one plane, in 3d you have 3 planes, so the outputed rotatedx/y from this formula will be applied to the next plane, and so on to have a final rotated coordinate in 3d

to rotate onthe x axis, you'll be rotating on a plane that only uses z and y values
on the y axis, it'll be x and z values etc...


simplified it would look like this

rx1 = basex
ry1 = basez * sin(xangle) + basey * cos(xangle)
rz1 = basez * cos(xangle) - basey * sin(xangle)

rx2 = rx1 * cos(yangle) - rz1 * sin(yangle)
ry2 = ry1
rz2 = rx1 * sin(yangle) + rz1 * cos(yangle)

rx3 = rx2 * cos(zangle) - ry2 * sin(zangle)
ry3 = rx2 * sin(zangle) + ry2 * cos(zangle)
rz3 = rz2

rxyz3 will be your final rotated coordinates


http://syn9.thingie.net/download/rot.bas

here is an example... please keep in mind that using this method as the sole way to do rotation per point is EXTREMELY slow, but it is the simplest way to explain rotation, but it should be a good primer into how 3d rotation works

for a lot more indepth information about 3d, id suggest checking out relsoft's tutorials:: http://qbnz.com/pages/tutorials/

hope that helps
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)