This is a rectangular area calculation given its 4 vertices’ coordinates (axis-aligned). I had to do some research on various how-tos.
#lang racket
(define rect1 '( (1 1) (5 1) (1 -2) (5 -2) ) )
(define xmin 'undefined)
(define xmax 'undefined)
(define ymin 'undefined)
(define ymax 'undefined)
(define (bounds point) (begin
(void (let
( (x (list-ref point 0))
(y (list-ref point 1)) )
(begin
(if (equal? xmin 'undefined) (set! xmin x) (if (< x xmin) (set! xmin x) '()) )
(if (equal? xmax 'undefined) (set! xmax x) (if (> x xmax) (set! xmax x) '()) )
(if (equal? ymin 'undefined) (set! ymin y) (if (< y ymin) (set! ymin y) '()) )
(if (equal? ymax 'undefined) (set! ymax y) (if (> y ymax) (set! ymax y) '()) )
)
) ) )
)
(bounds (list-ref rect1 0))
(bounds (list-ref rect1 1))
(bounds (list-ref rect1 2))
(bounds (list-ref rect1 3))
(list xmin xmax ymin ymax)
(- xmax xmin)
(- ymax ymin)
(* (- xmax xmin)
(- ymax ymin) )
Welcome to DrRacket, version 7.4 [3m].
Language: racket, with debugging; memory limit: 128 MB.
'(1 5 -2 1)
4
3
12
>
Lascia un commento
Devi essere connesso per inviare un commento.