@Louis

I must admit that I had forgotten about (or even never heard of) Brahmagupta's formula for the area of a cyclic quadrilateral. Treating Heron's formula as a special case of the former makes indeed an elegant solution.
Thanks for pointing that out.

-M

At 2018-09-05 01:25, you wrote:

I sent this message earlier today, but it seems that I used the wrong email address. I didn’t find it in the forum archives; sorry if it comes in twice.
I see that most of what I said has since been covered by Mike.

~~~~~~~~~~~~~~~~~~~~~~~~~~~

I would’ve done it this way; the semi-perimeter is not stored, but rather passed through the subtraction by subtracting 0.

   H=: [: %: -:@(+/) */ . - ,&0
   H 3 4 5


Heron’s formula is in fact a special case the more general Brahmagupta formula for calculating the area of a quadrilateral with sides a b c d inscribed in a circle:

A = sqrt( (s-a)(s-b)(s-c)(s-d) )

and a triangle is a quadrilateral with one side of length 0, and is always inscribed in a circle.
This formula I would implement like this:

   A=: %:@(*/ . -~ [: -: +/)
   A 1 1 1 1

   A 2 2 2 2

   A 3 4 5 0


In the last example of the same triangle as before, the semi-perimeter is effectively passed through the subtraction, inspiring the definition of H.

Louis

> On 4 Sep 2018, at 13:50, Martin Kreuzer <[email protected]> wrote:
>
> Hi all -
>
> To calculate the area of a flat triangle, using Heron's formula,
> A(a,b,c)= sqrt( s2*(s2-a)*(s2-b)*(s2-c) )
> I wrote a simple function doing this:
>
> * get the three sides (as list input y)
> * compute the half  perimeter s2
> * build the differences s2-y
> * build product
> * take square root
>
> My explicit solution looks like this
>
> taher=: 13 : '%: s2 * */ s2-y [ s2=. -: +/ y'
>
> and works
>
>   taher 3 4 5
> 6
>
> Suggested tacit version looks like this (and works too)
>
> tahert=: [: %: ([: -: +/) * [: */ ([: -: +/) - ]
>
> Q: Is there a way to reference the intermediate result of ([: -: +/) the half perimeter s2
> within the tacit expression, as has been done in the explicit..?
> [Guess the interpreter takes care of this anyway; my question aims at whether a shorter formulation could be reached.]
>
> Thanks
> -M
>
> ----------------------------------------------------------------------
> For information about J forums see http://www.jsoftware.com/forums.htm

----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm

----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm

Reply via email to