[futurebasic] Re: [FB] [FB II] Physics

Message: < previous - next > : Reply : Subscribe : Cleanse
Home   : December 2000 : Group Archive : Group : All Groups

From: Robin <robinc@...>
Date: Wed, 13 Dec 2000 10:22:41 +1000
> Peter Dempsey posted a physics question a few weeks back which
> caused me to dust off an old game I was working on and shelved
> because I was having the same problems as Peter. Since the list has
> been slow I thought I'd post my physics questions. I need to
> calculate the angle in degrees of an object and a second object. I
> also need to find the angle in degrees that an object is traveling.
> Since I'm using FB II, I only have access to SINE, COSINE, TANGENT,
> and ARC TANGENT. I discovered that all these functions return the
> result in radians and I need to convert to degrees. I haven't used
> these formulas in 35 years back in school and I've forgotten how to
> go about it. Any help would be appreciated.

This will calculate the angle in degrees given an x and y offset:

local
dim length#,sine#,radians#,degrees#
local fn CalcAngle# (dx,dy,pLength&)
    'given x and y lengths, calculate vector
    length# = sqr(dx*dx+dy*dy)
    sine# = dy/length#
    radians# = asin(sine#)
    degrees# = radians#/gAngletoradians#'-90 to +90°
    if dx<0 then degrees# = 180-degrees#
    pLength&.nil# = length#
end fn = degrees#

These conversion globals are useful:

gRadToDeg# = 180/pi
gAngletoradians# = pi/180

(pi is an inbuilt FB^3 double-precision value)
-- 
Robin
====================================================
Genesearch Pty Ltd
E-mail: robinc@...
WWW:    http://www.genesearch.com.au
====================================================