home *** CD-ROM | disk | FTP | other *** search
- From: akcs.joehorn@hpcvbbs.cv.hp.com (Joseph K. Horn)
- Date: Thu, 24 Dec 1992 07:40:03 GMT
- Subject: Re: solving triangles
- Message-ID: <2b39672f.2479.1comp.sys.hp48.1@hpcvbbs.cv.hp.com>
- Path: sparky!uunet!paladin.american.edu!gatech!swrinde!sdd.hp.com!hp-cv!hp-pcd!hpcvra!rnews!hpcvbbs!akcs.joehorn
- Newsgroups: comp.sys.hp48
- References: <10313@ncrwat.Waterloo.NCR.COM>
- Lines: 47
-
- john.Latala@Waterloo.NCR.COM [john Latala] writes:
-
- > I wrote a number of routines for solving various triangle
- > combinations....
- > The problem I'm having is coming up with a way to code the wrapper
- > program so it doesn't take forever to run....
- > This leads to 64 possible cases which makes for a rather large and
- > ugly case statement to say the least....
- > Can anybody think of an easier way of doing this kind of decoding?
-
- Coupla years ago I wrote a triangle solver just for fun that had a
- very simple user interface, led internally to only a handful of cases
- (was it 9?) and appeared to run instantaneously.
-
- Here's the idea; feel free to implement it if you wish. The six
- softkeys are SIDE A, ANGLE A, SIDE B, ANGLE B, SIDE C, ANGLE C. Type
- a number, press a softkey, and it turns black-on-white to represent
- that it's got a value. Press 0 and a softkey to "turn it off". As
- soon as the third value is entered, the program automatically
- calculates the other three and puts them (tagged) on the stack and
- sets up for another go. It wasn't a very big loop.
-
- I remember now; the cases called subroutines that contained all the
- necessary trig, like the law of cosines, in its four basic forms, and
- the law of sines, in its two basic forms. Local variables obviate the
- need for "duplicates" like these three:
-
- a = SQRT(b^2 + c^2 - 2*b*c*COS(A)) (1)
- b = SQRT(a^2 + c^2 - 2*a*c*COS(B)) (2)
- c = SQRT(a^2 + b^2 - 2*a*b*COS(C)) (3)
-
- These are "formally" identical, so they can be coded just once, using
- local variables, and then called from anyplace and passed any values,
- even if the variable names don't agree; only the stack position would
- be important, not the names. Of course, this subroutine would be
- called SAS, and take two sides and their included angle as input, and
- yield the third side as the output, e.g.
-
- b c A SAS 'a' STO for (1) above
- a c B SAS 'b' STO for (2) above
- a b C SAS 'c' STO for (3) above
-
- The SAS routine could be as simple as this:
-
- << -> a b C 'SQRT(a^2+b^2-2*a*b*COS(C))' >>
-
- Good grief, I'm doing your homework for you. ;-) -jkh-
-