Dark Bit Factory & Gravity
PROGRAMMING => General coding questions => Topic started by: Tetra on March 12, 2007
-
I just cant get my head round the maths behind the rigid body, i'm just too thick when it somes to math and math symbols. Wonder if someone could perhaps explain or show me what it means cos I dont have a clue.
I'll start by explaining what I done so far and post some links to the definations, and then if someone wouldnt mind telling me how badly I done :D
These are the links i've been looking at:-
Acceleration (http://en.wikipedia.org/wiki/Acceleration)
Velocity (http://en.wikipedia.org/wiki/Velocity)
Torque (http://en.wikipedia.org/wiki/Torque)
Rigid body dynamics (http://en.wikipedia.org/wiki/Rigid_body_dynamics)
I have absolutely no idea what I am doing, I dont understand the equations for Rigid body dynamics at all.
Here is some code, i've cut it down to simplify it, if I ever get it working i'll post the full code to it.
Square\dx# and Square\dy# is the velocity vector ( from the center of the square )
Square\odx# and Square\ody# is the previous velocity vector ( from the center of the square )
; Assuming a collision is detected do the following
; fyi all the vectors origin is at the center of the square
;
; Square\timePassed# = Milliseconds passed so divide with 1000 to convert to seconds
;
; Force = Mass * Acceleration
; Acceleration is the rate of change in velocity over time a = v/t
;
Square\velocity# = VectorLength#( Square\dx# - Square\odx#, Square\dy# - Square\ody# )
Square\acceleration# = Square\velocity# / ( Square\timePassed# / 1000.0 )
Square\force# = Square\mass# * Square\acceleration#
;
; Angle between the velocity vector and point of impact vector
;
angle# = -getAngle( impactX#,impactY#, Square\dx#, Square\dy#, 0,0 )
;
; torque = distance to center * Force * sin( angle )
;
distance# = VectorLength#( impactX#, impactY# )
Square\torque# = Square\force# * distance# * Sin( angle# )
;
; Convert torque to angular velocity
;
Dunno how to do this
;
; Returns the length of a 2d vector
;
Function VectorLength#( x#,y# )
Return Sqr#( x# * x# + y# * y# )
End Function
;
; gets the angle between two vectors
; x1,y1 vector 1, x2,y2 vector 2, ox,oy origin
;
Function getAngle#( x1#,y1#, x2#,y2#, ox# = 0,oy# = 0 )
Local tvAx# = x1# - ox#
Local tvAY# = y1# - oy#
Local tvBx# = x2# - ox#
Local tvBY# = y2# - oy#
Local d# = ATan2#( tvAy#, tvAx# )
Local tvCx# = Cos#( d# ) * tvBx# + Sin#( d# ) * tvBy#
Local tvCy# = -Sin#( d# ) * tvBx# + Cos#( d# ) * tvBy#
Local newAngle# = ATan2#( tvCy#, tvCx# )
If ( newAngle# > 0.0 )
newAngle# = -(180.0 - newAngle#)
Else
newAngle# = -(-180.0 - newAngle#)
EndIf
Return newAngle#
End Function
Some insight would be much appreciated :)
-
It's a hard one isnt it :updance:
-
Looks like it!
-
Only just noticed this bit of the forum!
Looks reasonable to me so far Tetra!
Jim
-
Too convert Torque (angular momentum) to motion you need to know the radius its the same as speed formula ...
Torque = (Pi*Radians) / time (this is angular momentum)
torque is usually measured in RPM so use 60(seconds) / 1000 (mileseconds) to gain your basic unit of time
now if you have the Torque and you are rotating a ball the radius*Torque is equal to distance travelled if the ball does not skid but rolls along a frictionless surface ...
Distance = Radius*Torque = Radius * (PI*Radians) / time (this is motion)
Edit -
i will clean up the last one for ya. get rid of the if statements and do the atan like this instead ...
atan(cos(x1), -sin(y2))
something like that will keep it in the right polarity