Newsgroups: comp.sys.hp48
From: bd628@torfree.net (Bill Markwick)
Subject: Two Point Geometry Program
Message-ID: <F1wLHn.FGJ.0.sheppard@torfree.net>
Organization: Toronto Free-Net
X-Newsreader: TIN [version 1.2 PL2]
Date: Wed, 4 Nov 1998 15:24:59 GMT
Lines: 77
Xref: republic.btigate.com comp.sys.hp48:18197

Inspired by Chris's recent post, I wrote a program that takes any two
points and returns the function, the slope, the distance, and the X and
Y intercepts; it also stores them as global variables. A PRGE program
deletes all the created vars. PLOTF plots the function using autoscale
(it overwrites EQ).

I hope it's useful for geometry, or an example of programming (it
probably could be more efficient in finding solutions).

On that last point: there's a function sigma\LINE that will find
a function given a 2 x 2 matrix - it sounds as if this would be much more
concise than the method I used, but in fact it's somewhat larger by the
time you get through making the matrix, even allowing for my multiple
EXPAN COLCT statements (some functions need them twice for
simplification).

If nothing else - it lends itself to deletions. For one thing, you can
get rid of all the DUP 'varname' STO lines if you don't want stored
variables.

Enjoy,

Bill


Checksum and size on stack: #72Fh, 698 bytes.   Nov/98.

%%HP: T(3)A(R)F(.);
\<<
  IFERR 'X' PURGE         @ Encloses program in error handler for clean
"2 pts \-> Funct, Slope,  @ exits; purges any existing X variable.
Dist, Ints, Plot."
{
":x,y:(,)                 @ Gets two points in familiar (x,y) format.
:x1,y1:(,)"
{ 1 7 } ALG V }           @ Cursor position and syntax checking.
INPUT OBJ\-> DTAG         @ Removes tags/brackets and puts four
SWAP DTAG OBJ\-> 3        @ numbers on the stack.
ROLL OBJ\-> \-> x y x1    @ Stores them as local variables.
y1
    \<< '(y-y1)/(x-x1     @ Finds slope.
)' EVAL DUP 'X-x1'        @ Finds function using slope/point. X is
EVAL * y1 + EXPAN         @ a symbolic variable.
COLCT EXPAN COLCT
DUP 'Fnct' STO            @ Next four lines tag and store the
"Fnct" \->TAG SWAP        @ function and slope.
DUP 'Slpe' STO
"Slope" \->TAG '\v/((y-   @ Finds distance between points.
y1)^2+(x-x1)^2)'
EVAL
    \>> DUP 'Dist'        @ Tags and stores distance.
STO "Dist" \->TAG 3
PICK { X 0 } | 0          @ Copies function to level 1 and sets
SWAP R\->C DUP 'Yint'     @ X to zero to find Y intercept as (0,Y).
STO "Y-int" \->TAG 4      @ Tags and stores Y intercept.
PICK 'X' 0 ROOT 0         @ Copies function to level 1 again and
R\->C "X-int" \->TAG      @ sets fnct=0 to find X intercept.
DUP 'Xint' STO 'X'        @ Tags and stores X intercept.
PURGE                     @ Purges the X variable created by ROOT.
    \<< { PICT PPAR }     @ Plot program using autoscale.
PURGE Fnct STEQ           @ - Note that it overwrites EQ.
FUNCTION AUTO DRAX
DRAW PICTURE 'X'          @ Also purges X variable created by autoscale.
PURGE
    \>> 'PLOTF' STO       @ Stores plot program as PLOTF.
    \<< { Xint Yint       @ Program to purge created variables.
Dist Slpe Fnct
PLOTF PRGE } PURGE
    \>> 'PRGE' STO        @ Stores purge program as PRGE.
  THEN 2 DROPN            @ Cleans up stack if program cancelled.
  END
\>>

-- 
- Bill Markwick,  Toronto, Ontario, Canada  -  bd628@torfree.net
  Visit my Folk File, a large online dictionary of folk music terms:
          http://www.cgrg.ohio-state.edu/~spencer/FF/