Too dumb to do the maths

BlitzMax Forums/BlitzMax Beginners Area/Too dumb to do the maths

Qweeg(Posted 2005) [#1]
Apologies as I am sure this is simple, but I have been thinking about it for too long, and now I have a total blank.

I have 2 angles and I just need to know how close they are to being at right angles to each other. The angles could be positive or negative, but I am just need to return a value between 0 and 90.

Any help would be much appreciated


LarsG(Posted 2005) [#2]
subtract one from the other?


Qweeg(Posted 2005) [#3]
No - I can't really just do that. For example if the angle between two objects is 170 and the angle that object one is travelling along is 20 then simply subtracting one from the other gives 150. But in this example I would want to return 30.

I guess from this I could maybe get the absolute difference between the two angles and then look at which 90 degree quadrant the resultant angle is in and depending on which one it falls in do the following:

RESULTANT ANGLE ACTION
< 90 : do nothing
> 90 and <= 180 : 180 - result
> 180 and <= 270 : result - 180
> 270 and <= 360 : 360 - result

I think this will always give me how close the object paths are to being at right angles to each other. Does this look right to anyone else (or even make sense to anyone)?


Tibit(Posted 2005) [#4]
0 to 90? But what if they are 180 degrees apart?

A# = Abs( V1 - V2 ) Mod 90 ' Is this what you want?

btw What are you doing?


Qweeg(Posted 2005) [#5]
hi wave,

Thanks, I had tried that actually but it doesn't seem to work in all scenarios - I think because the modulus gives the same result for angles that are 90 degrees apart as it does for 180 (your example), when in fact these are opposites.

This is to do with collisions and elasticity really, so maybe it will be clearer with an example:

If a moving ball (cue ball for example) collides with a static one, and the cue ball has backspin applied, then depending on how full the impact depends on how much the backspin will affect the subequent motion of the cue ball.

What I mean is that if the balls strike head on then the cue ball would move backwards after the collision. However if it were to just strike a glancing blow, the effect of backpin would be minimal and the ball would continue to move forwards.

Looking at things in this way the moving ball can effectively strike the other ball at an angle between 0 and 90(+/-) degrees - with 0 being a head on collision and 90 being the faintest of glancing contacts.

But obviously the angle between the balls on contact and the angle the moving ball is travelling at can both be any angle so I need a way to convert the difference into a 0-90 range.

Hopefully this makes it a bit clearer. As you may guess this relates to a pool game. I have all the effects of sidespin and top and backspin working (albeit in a 'fake' physics way), except for taking into account how the speed of the cue ball is altered by the fullness of the contact.


Curtastic(Posted 2005) [#6]
I think you can use this
'angles must be between 0 and anglemax
Function AngleDifference#(angle1#,angle2#,anglemax=360)
	Local temp#

	temp#=angle2-angle1
	If temp>+anglemax/2 Then Return temp-anglemax
	If temp<-anglemax/2 Then Return temp+anglemax
	Return temp
EndFunction

howclosetorightangle=abs(90-abs(angledifference(a1,a2)))



Qweeg(Posted 2005) [#7]
Thanks guys for all the help.

Coorrae - top notch stuff! This seems to work for me. Thanks loads.