> I saved it from Notepad. (Is that a mistake? Anyone got a better
> editor to suggest?)
Since you're using Lahey/Fujitsu, why not also use the Fortran-aware
editor ("ed", I think) that comes with the Windows version? In Linux I
use NEdit. Many of my colleagues like emacs.
> theta = ACOS((x**2+y**2-z**2)/(2.0*x*y))
> height = x*SIN(theta); Area = 0.5*y*height
I'd use Heron's formula:
s = 0.5 * ( x + y + z )
area = sqrt ( s * ( s - x ) * ( s - y ) * ( s - z ) )
but this might suffer overflow in the argument for the sqrt even though
the area doesn't overflow. One possibility is to divide the square root
into two factors:
area = sqrt ( s * ( s - x ) ) * sqrt ( ( s - y ) * ( s - z ) )
At the expense of three divides, I think you can guarantee that no
intermediate result overflows unless the area would overflow:
area = s * ( s * &
& sqrt ( ( 1.0 - x / s ) * ( 1.0 - y / s ) * ( 1.0 - z / s ) ) )
The grouping of factors is important to avoid overflow, because the
result of the sqrt is going to be less than 1.
Even so, as Dick suggested, it would be a good idea to make sure that
all of x, y and z are positive.
See http://mathworld.wolfram.com/TriangleArea.html for other formulae.
--
Van Snyder | What fraction of Americans believe
[log in to unmask] | Wrestling is real and NASA is fake?
Any alleged opinions are my own and have not been approved or disapproved
by JPL, CalTech, NASA, Frederick Gregory, George Bush, or anybody else.
|