Polygon area

Description

Area is the area of the polygon enclosed by the list of points chain, where the coordinates of each point are represented by a pair (X,Y) of integers.

Source: The Art of Prolog

Download

Program source code: polygon_area.pl

Listing

/*
   area(Chain,Area) :- 
	Area is the area of the polygon enclosed by the list of points
	Chain, where the coordinates of each point are represented by 
	a pair (X,Y) of integers.
*/
     area([Tuple],0).
     area([(X1,Y1),(X2,Y2)|XYs],Area) :-
        area([(X2,Y2)|XYs],Area1), 
        Area is (X1*Y2-Y1*X2)/2 + Area1.
 
%  Program 8.8  Computing the area of polygons

Comments

pl/prolog/pllib/polygon_area.txt · ostatnio zmienione: 2017/07/17 08:08 (edycja zewnętrzna)
www.chimeric.de Valid CSS Driven by DokuWiki do yourself a favour and use a real browser - get firefox!! Recent changes RSS feed Valid XHTML 1.0