Shoelace formula for polygonal area: Difference between revisions

(J draft)
Line 161:
30.0
>>> </lang>
=={{header|Racket}}==
<lang racket>#lang racket/base
 
(struct P (x y))
 
(define (area . Ps)
(define (A P-a P-b)
(+ (for/sum ((p_i Ps)
(p_i+1 (in-sequences (cdr Ps)
(in-value (car Ps)))))
(* (P-a p_i) (P-b p_i+1)))))
(/ (abs (- (A P-x P-y) (A P-y P-x))) 2))
 
(module+ main
(area (P 3 4) (P 5 11) (P 12 8) (P 9 5) (P 5 6)))</lang>
 
{{out}}
<pre>30</pre>
 
=={{header|REXX}}==
<lang rexx>/*REXX program uses a Shoelace formula to calculate the area of an N-sided polygon. */
569

edits