Codesnippets > Math

Difference between 2 angles

(1/1)

Kitty Hello:
Assume you have 2 angles (and degrees) and you want the difference angle from phi1 to phi2, but also keep the sign for the direction (clockwise or anticlockwise). This function should return the difference angle in a range -180.0 to +180.0 degrees.

--- Code: (glbasic) ---// distance between 2 angles
FUNCTION DistAngle: phi1, phi2
LOCAL dif = FMOD(phi2-phi1, 360.0)
IF dif<-180 THEN dif = 360.0 + dif
IF dif>180.0 THEN dif = 180.0 - dif
RETURN dif
ENDFUNCTION

--- End code ---
{"ft_lang_label":"__label__en","ft_lang_prob":0.7579323,"math_prob":0.97148794,"size":592,"snap":"2021-31-2021-39","text_gpt3_token_len":175,"char_repetition_ratio":0.12244898,"word_repetition_ratio":0.0,"special_character_ratio":0.32263514,"punctuation_ratio":0.12173913,"nsfw_num_words":0,"has_unicode_error":false,"math_prob_llama3":0.9868053,"pos_list":[0],"im_url_duplicate_count":[null],"WARC_HEADER":"{\"WARC-Type\":\"response\",\"WARC-Date\":\"2021-09-20T03:16:48Z\",\"WARC-Record-ID\":\"<urn:uuid:4715150b-f038-4bf4-8e08-11c1f91a7de8>\",\"Content-Length\":\"2135\",\"Content-Type\":\"application/http; msgtype=response\",\"WARC-Warcinfo-ID\":\"<urn:uuid:277ae2c7-83c7-4514-bd2d-89912345dab9>\",\"WARC-Concurrent-To\":\"<urn:uuid:bfaa789c-3aac-493a-b10a-9739f59ebd5d>\",\"WARC-IP-Address\":\"81.169.145.79\",\"WARC-Target-URI\":\"https://www.glbasic.com/forum/index.php?PHPSESSID=6s7umdfjauklrdnrtihjepqfk6&topic=7551.0;wap2\",\"WARC-Payload-Digest\":\"sha1:P3KG5JTIVU7JXPR6KKW3EP2ZUJSZI5OT\",\"WARC-Block-Digest\":\"sha1:YUR4H3VAOAKEVDR7MHA4UHTHEGHMVTW5\",\"WARC-Identified-Payload-Type\":\"application/xhtml+xml\",\"warc_filename\":\"/cc_download/warc_2021/CC-MAIN-2021-39/CC-MAIN-2021-39_segments_1631780056974.30_warc_CC-MAIN-20210920010331-20210920040331-00429.warc.gz\"}"}