home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #31 / NN_1992_31.iso / spool / comp / sys / hp48 / 6490 < prev    next >
Encoding:
Internet Message Format  |  1992-12-24  |  2.5 KB

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