Rotating a point about an axis or three.

BlitzMax Forums/BlitzMax Beginners Area/Rotating a point about an axis or three.

Ryan Burnside(Posted 2006) [#1]
Ok so I'm fairly new to the whole concept of mapping points in 3D along a 2d plain. I'll tell you my problem and what i know already in hopes that somebody can assist me. I want to plot a poing on a 2d plain with regards to the direction and angle the point is away from each of the three axis points. The camera is perpinducular to the plain, in essence top down.

To make a point rotate about the x axis. i use the following formula:
y=center_y+sin(angle)*distance_away

To rotate a point along the y axis I use this formula:
x=center_x+cos(angle)*distance_away


Now it would appear if you used both previous formulae together with a common angle you would be able to rotate the x and y points along the virtual z axis. (This axis being perpindicular the the camera or eye)

However, I can't figure out how to find the x and y positions of a given point while playing with all three of the rotations at once.

Please understand I don't really care about making a fancy 3D engine I just want some graphing calculation. I'n not out to write the next Blitz3D. I'n not trying to be a n00b with a grand illusion, I'm just VERY interested in the math.

I looked a bit into some things on Wiki and I'm not compleatly sure how to approach it. If you feel you have time to help me please do. I might be able to learn more quickly visually if you'd want to whip up an example.


bradford6(Posted 2006) [#2]
This might be in the wrong forum my friend. (maybe the OpenGL forum)

I will try to help.

If you are referring to raw openGL 3D rotations, you should look at Matrices, Euler Rotations and Quaternions. Each method has + and - depending on the application.

If you are really interested in the Math involved I suggest the following 3 course meal

1. Learn Vectors (start with 2D Vectors)
2. Learn Matrices (again, start with 2D first)
3. Learn Quaternions

wouldn't hurt to brush up on some Trigonometry since everything is based on triangles.

sorry for the mile high approach but I am not 100% sure what you are trying to learn.


Ryan Burnside(Posted 2006) [#3]
I'm just trying to make points rotate using ONLY blitzmax. No special software, they were able to do 3D on the Atari without any special 3D software why can't it be done on Blitzmax? I'm not inerested in polygons just rotation points.


Ryan Burnside(Posted 2006) [#4]
Ok I have created a demo to demonstrate what I do know. It will show rotation along the three demensions. I need to know how to plot a point from 3 given distances from each axis and an angle away from each axis. There HAS to be a formula for 3D plotting somebody had to write 3D software originally.
Lets say i have a point in the form of x,y,z and angles a1,a2,a3 how would I plot it?

What I can show so far:
http://www.ex0.biz/uploads/1106/1164264799.zip


Brendane(Posted 2006) [#5]
Perhaps nobody understands your question. Bradford6 gave you some good pointers and it seems from your demo that you understand how to compute a rotation about one axis.

"However, I can't figure out how to find the x and y positions of a given point while playing with all three of the rotations at once."
- I don't understand your question - would you care to rephrase it?


bradford6(Posted 2006) [#6]
simply put. 2D rotations are blazingly simple. You have a single point that represents a single axis and you determine the distance from that axis using a radius. use the mousewheel to grow/shrink the circle.


Global GW = 640 , GH = 480 , midw = GW/2 , midh = GH/2
Global xend , yend
Graphics GW,GH,0
Local frametimer = CreateTimer(30)
Global radius = 10
Repeat
	
	mx = MouseX()
	my= MouseY()
	
	radius = 20+ MouseZ()	
	angle#:+.1
	
	xend = midw+Cos(angle#)*radius
	yend = midh+Sin(angle#)*radius

	
	DrawText "x="+xend+" y="+yend,xend,yend
	DrawText "Radius="+radius,xend,yend+20
	DrawText "Angle="+angle,xend,yend+40

	
	DrawLine(midw,midh,xend,yend)


	WaitTimer(frametimer)
	Flip ; Cls
Until KeyDown(KEY_ESCAPE)





for 3D, there are 3 axes for every point. Each axis can be a part of a global coordinate system (the world) or a local coordinate system (the object). 3D rotations are called 'transforms'. It is not really as simple as doing sin/cos for each of the 3 axes. that can be very messy and difficult to maintain. hence the Euler method, Matrices and Quaternions I mentioned above. Each method has pro's and cons. I would save Quats for last because they are more difficult to visualize (Eulers make more *spatial* sense)


Ryan Burnside(Posted 2006) [#7]
OK
I cane across this earlier this week and it inspired the whole thing.

http://en.wikipedia.org/wiki/3D_projection

Would anyone be able to tell me if this is the code I need?


tonyg(Posted 2006) [#8]
Yes, which is why Bradford6 suggested looking up Matrices.


Ryan Burnside(Posted 2006) [#9]
ok here is my code. It doesn't seem to work, I meant to plot a 3d point using the Wiki's last and simple way of plotting.


This is the page again. It's the last formula the "simple version" http://en.wikipedia.org/wiki/3D_projection



Function point_3d(cam_x#,cam_y#,x3d#,y3d#,z3d#)
Local distance_x#=cam_x-x3d
Local distance_y#=cam_y-y3d
Local eye_distance#=distance_x/distance_y
Local final_x#= x3d- ((distance_x/(z3d+eye_distance)) * x3d)
Local final_y#= y3d- ((distance_y/(z3d+eye_distance)) * y3d)
SetColor 255,255,255
DrawOval final_x-1,final_y-1,2,2	
End Function

Have I made a mistake while translating it into code?