User:Devon McCormick/Geometry2

From J Wiki
Jump to: navigation, search

Some comments on the Geometry page.

I see now why I was unable to use the area function correctly. I first cut-and-pasted the definition

   area=:[: +/ (-&{: -:@* +&{.)~ Atnp

When I noticed the reference to another definition Atnp, I then pasted that into my session.

NB.*Atnp a applies verb dyadically to neighbouring pairs (including first and last)
Atnp=:(/\) (2&) (@(, {.))

So, my attempt to use area gave me the following error:

   area 1 1 _1 _1*-:%:2 0,0 2,2 0,:0 2
|domain error: Atnp
|       area 1 1 _1 _1*-:%:2 0,0 2,2 0,:0 2

Once I defined area again, having previously defined the adverb Atnp, it worked fine.

   area=:[: +/ (-&{: -:@* +&{.)~ Atnp
   area 1 1 _1 _1*-:%:2 0,0 2,2 0,:0 2
1

I also defined my own version of this verb, using essentially the same method (Surveyor's Formula) but with an equivalent to Atnp incorporated directly into it.

Signed area that works on 2-column point array:

areapts=: [:([: -:[: +/(0{]) * [:(1&|.-_1&|.) 1{]) |:

   areapts 2 0,2 4,0 4,:0 0         NB. 2x4 square
8