From: "Jeff Roulston" <jeff@lemcke.bu.aust.com>
Newsgroups: comp.sys.hp48
Subject: Section property calculator for (ir)regular polygons <LONG>
Date: Sun, 1 Nov 1998 20:30:55 +1000
Organization: OzEmail Ltd.
Lines: 229
Message-ID: <71hdd7$k5a$1@reader1.reader.news.ozemail.net>
NNTP-Posting-Host: slsun52p15.ozemail.com.au
X-Newsreader: Microsoft Outlook Express 4.71.1712.3
X-MimeOLE: Produced By Microsoft MimeOLE V4.71.1712.3
Xref: republic.btigate.com comp.sys.hp48:18076

The following is a program  which may be useful to those who need to
calculate section properties for irregular (or regular for that matter)
shapes. Documentation is included below. This is my first significant
User-RPL project, so please bear with me if I have overlooked some of the
finer points.

Regards,

Jeff


Sectn v1.0

November '98


Overview:
=========

This program was inspired by the program AREA (on GD #9 \Math) by Dewayne
Cushman, which calculated the area of an irregular polygon. I have often
needed to calculate additional section properties for such shapes, and until
now had to resort to a PC package.

For an irregular polygon, the program below takes a matrix from the stack
(see "Usage" for details) and calculates the centroid location, area, second
moments of area, radii of gyration, principal moments of area and angle to
the principal axis.

I hope you find Sectn useful.


DISCLAIMER:
===========

The program is written entirely in User RPL, so it should not pose any
threat to memory contents. It has been tested on HP48G ROM revisions P and R
without any trouble. As always, use at your own risk. No responsility is
accepted for any loss of memory, or failure of the program to fulfill the
intended function.

Installation:
=============

Simply transfer the User RPL object below to your HP48 as Sectn (or any
other name). As some G-specific list processing commands are used, I do not
believe that the program will run on the SX series without modifications.
Sorry.

Bytes: 3061.5
Chksum: # BE20h

Compressed using BZM, the program uses about 1009 bytes on my GX.


Usage:
======

Using the matrix writer, enter the coordinates of each vertex of the polgon
with respect to an arbitrary origin and moving in a _clockwise_ direction.
(X-coordinates in the first column, y-coordinates in the second.) Repeat the
first point as the last point, to close the section. Put the matrix on the
stack, and execute the program.

Eventually the following will be displayed in the small font:

IXC:    The moment of inertia about the x-axis through the centroid.
IYC:    The moment of inertia about the y-axis through the centroid.
IMAX:   The moment of inertia about the principal axis through the centroid.
IMIN:   The moment of inertia about the second principal axis.
ALPHA:  The angle between the principal axes and the x-axis.
RX:     Radius of gyration about the x-axis through the centroid.
RY:     Radius of gyration about the y-axis through the centroid.
AREA:   The area of the section.
XC:     The x-offset from the origin to the centroid.
YC:     The y-offset from the origin to the centroid.

Press CANCEL to clear the small font display and the return to the stack.
The above values are left on the stack, each tagged with their name.

Tip: Closed sections may be entered by "cutting" a wall and proceeding
around the perimeter as for any other polygon. This will lead "inside" the
section at the cut, around the interior and out again at the cut. (There
will then be two pairs of vertices with the same coordinates.)

WARNING: The program stores the input matrix in the statistics matrix
(\GSDAT), and will overwrite any previous contents.


Known problems and limitations:
===============================

* G-series only
* "Infinite result" may be returned during calculation of alpha unless
flag -22 is set


Background:
===========

The calculation method used occurred to me one morning at about 3am - this
was a problem that had been bothering me for some time. The program
considers sequentially the trapeziums bounded by a side of the polygon, a
vertical axis at the left of the section, and horizontal axes at the top and
bottom of the side under consideration. Ix, Iy, Ixy, A etc are calculated
for the triangle and rectangle composing each trapezium.  These values are
positive or negative depending on the direction of the side of the polygon,
hence the CASE structure at the core of the program. I have identified four
separate cases, and while some of the code is common between clauses of the
CASE, there are some subtle differences to end up with the correct signs.
The code could no doubt be refined, but I have elected to keep the four
cases clearly defined and put up with the extra bytes.

Results have been cross checked against published section properties for
various structural sections, and textbook formulas for a lot of different
shapes. I am not aware of any situations where the algorithm will fail, but
unfortunately this does not mean it is foolproof.

To display the 10 lines of results, the program ends with an extract of the
STKV program from the HP48 Handbook, by James Donnelly.


Feedback:
=========

For more info (not that there is much more to be said), bug reports,
feedback etc, email me: jeff@lemcke.bu.aust.com.


Regards,

Jeff Roulston



%%HP: T(3)A(D)F(.);
\<< DUP '\GSDAT' STO
MIN\GS OBJ\-> DROP \->
XMIN YMIN
  \<< DUP SIZE OBJ\-> DROP DROP { } + DUP
XMIN NEG CON SWAP YMIN NEG CON ROT
\->COL DROP ROT + ROT ROT + SWAP 2 COL\->
OBJ\-> OBJ\-> DROP2 1 -
\-> N
    \<< { } { } { } { } { } { } 1 N
      START \-> X2 Y2 X1 Y1 AN XN YN IXN IYN IXYN
        \<< X2 Y2
          CASE X2 X1 \>= Y2 Y1 \>= AND
            THEN X1 Y2 Y1 - * X2 X1 -
Y2 Y1 - * 2 / AN + + X1 2 / X1 X2 X1 -
3 / + XN + + Y2 Y1 - 2 / Y1 + Y1 Y2 -
3 / Y2 + YN + + X1 Y2 Y1 - 3 ^ * 12 /
X2 X1 - Y2 Y1 - 3 ^ * 36 / IXN + + Y2
Y1 - X1 3 ^ * 12 / Y2 Y1 - X2 X1 - 3 ^
* 36 / IYN + + 0 X2 X1 - SQ Y2 Y1 - SQ
* 72 / IXYN + +
            END X2
X1 \>= Y2 Y1 < AND
            THEN X1
Y2 Y1 - * X2 X1 - Y2 Y1 - * 2 / AN +
+ X1 2 / X1 X2 X1 - 3 / + XN + + Y1 Y2
- 2 / Y2 + Y1 Y2 - 3 / Y2 + YN + + X1
Y2 Y1 - 3 ^ * 12 / X2 X1 - Y2 Y1 - 3 ^
* 36 / IXN + + Y2 Y1 - X1 3 ^ * 12 /
Y2 Y1 - X2 X1 - 3 ^ * 36 / IYN + + 0 X2
X1 - SQ Y1 Y2 - SQ * 72 / IXYN + +
            END X2
X1 < Y2 Y1 < AND
            THEN X2 Y2 Y1 - * X1 X2 -
Y2 Y1 - * 2 / AN + + X2 2 / X2 X1 X2 -
3 / + XN + + Y1 Y2 - 2 / Y2 + Y2 Y1 -
3 / Y1 + YN + + X2 Y2 Y1 - 3 ^ * 12 /
X1 X2 - Y2 Y1 - 3 ^ * 36 / IXN + + Y2
Y1 - X2 3 ^ * 12 / Y2 Y1 - X1 X2 - 3 ^
* 36 / IYN + + 0 X1 X2 - SQ Y1 Y2 - SQ
* NEG 72 / IXYN + +
            END X2
X1 < Y2 Y1 \>= AND
            THEN X2 Y2 Y1 - * X1 X2 -
Y2 Y1 - * 2 / AN + + X2 2 / X2 X1 X2 -
3 / + XN + + Y2 Y1 - 2 / Y1 + Y2 Y1 -
3 / Y1 + YN + + X2 Y2 Y1 - 3 ^ * 12 /
X1 X2 - Y2 Y1 - 3 ^ * 36 / IXN + + Y2
Y1 - X2 3 ^ * 12 / Y2 Y1 - X1 X2 - 3 ^
* 36 / IYN + + 0 X1 X2 - SQ Y2 Y1 - SQ
* NEG 72 / IXYN + +
            END
          END
        \>>
      NEXT
    \>> \-> A X Y IX IY
IXY
    \<< DROP2 A Y * \GSLIST A \GSLIST / A X
* \GSLIST A \GSLIST / \-> YBAR XBAR
      \<< Y YBAR - SQ A * IX + \GSLIST
"Ixc" \->TAG X XBAR - SQ A * IY + \GSLIST
"Iyc" \->TAG IXY X XBAR - Y YBAR - * A
* - \GSLIST DUP SQ 4 * 4 PICK 4 PICK -
SQ + \v/ 2 / 4 PICK 4 PICK + 2 / DUP 3
PICK + "Imax" \->TAG ROT ROT SWAP -
"Imin" \->TAG 3 PICK 2 * 5 PICK 7 PICK -
/ ATAN 2 / "Alpha" \->TAG 6 PICK A \GSLIST
/ \v/ "rx" \->TAG 6 PICK A \GSLIST / \v/
"ry" \->TAG A \GSLIST "Area" \->TAG XBAR
XMIN + "xc" \->TAG YBAR YMIN + "yc"
\->TAG 9 ROLL DROP
PICT RCL PPAR \->
pictsav ppar
        \<< PICT PURGE 1 32 XRNG 1
64 YRNG 1 10 6 1 \-> rowht tsize
          \<<
            FOR i PICT 1 i rowht *
R\->C RCLF STD i ": " + SWAP STOF i 3 +
PICK \->STR + tsize \->GROB GOR
            NEXT { } PVIEW 'PPAR'
PURGE ppar
            IF
'PPAR' SAME NOT
            THEN
ppar 'PPAR' STO
            END
pictsav PICT STO
          \>>
        \>>
      \>>
    \>>
  \>>
\>>