Tcl Library Source Code

View Ticket
Login
Ticket UUID: df3676c9821ba917c5cfda68c2ea0ad7a6947ac9
Title: trig angle reduction in degrees or radians
Type: Patch Version: TCLLIB 1.5
Submitter: gold Created on: 2017-12-04 22:02:38
Subsystem: math :: geometry Assigned To: arjenmarkus
Priority: 5 Medium Severity: Cosmetic
Status: Closed Last Modified: 2021-03-14 13:31:45
Resolution: Fixed Closed By: arjenmarkus
    Closed on: 2021-03-14 13:31:45
Description:
math::geometry(n) 1.2.2 tcllib "Tcl Math Library"
subj: trig angle reduction in degrees or radians
# Angle reduction in degrees or radians might be convenient to some TCLLIB users. Maybe these angle reduction functions are already available in other TCL libraries, but not known to me (from some docs and later textbooks). As noted on the ticket entry, these proposed changes are cosmetic and do not interfere with existing user programs. 

# Code below was loaded on tcl wiki under page on Trig Procedures for degree measures as sind, cosd, tand,etc.
I'll "fish" for some improvements.
    # start of file
    proc degree_reduction {aa} {
    if { $aa > 0. } {
    while {$aa > 360.} {
    set aa [- $aa 360.] }
    return $aa }
    if { $aa < -360. } {
    while {$aa < -360.} {
    set aa [+ $aa 360.] }
    return $aa }}
    proc pi {} {expr acos(-1)} from AMG
    proc radian_reduction {aa} {
    set pi [pi]
    if { $aa > 0. } {
    while {$aa > [* 2. $pi ] } {
    set aa [- $aa [* 2. $pi ] ] }
    return $aa }
    if { $aa < [* -1. 2. $pi ]  } {
    while {$aa < [* -1. 2. $pi ] } {
    set aa [+ $aa [* 2. $pi ] ] }
    return $aa }}
    # end of file
User Comments: arjenmarkus added on 2021-03-14 13:31:45:
This was solved already (see comments) - I should have closed the ticket.

anonymous (claiming to be gold) added on 2018-07-25 20:11:09:
to akupries 
subj. are examples needed on wiki or man page?
 
Thank you. This seems really exciting work, which will keep TCL in pace with
some of the other brand name (math oriented) languages. However, are examples needed on wiki or TCL/TCLLIB/UNIX man page? Probably I should revamp cited wiki page to reference your recent TCCLIB contribution. Thanks again, gold

arjenmarkus added on 2018-07-23 06:46:44:
I have now implemented a more direct version of such a reduction procedure for arguments in both radians and degrees. Part of the new math::trig package that contains a lot more mathematical functions - see ticket  https://core.tcl-lang.org/tcllib/tktview/21fef042b91ca252fc2a20ead5cd05c2b51b1776

The package is part of Tcllib's math module.

arjenmarkus added on 2018-07-20 08:46:33:
A drawback of this method is that roundoff errors will accumulate if the angles are large. Furthermore, perhaps more important, the calculation can be done quite efficient by simply calculating the number of 2pi's that are needed.

aku added on 2018-07-09 19:28:38:
Arjen, could you have look at this, please ?

Attachments: