cad_parea [-i input] [-o output]
CAD_PAREA(1)
NAME
cad_parea - compute the area of a polygon
On this page
SYNOPSIS
DESCRIPTION
cad_parea reads a series of 2D polygon vertex coordinates (x y, one pair per line, whitespace separated) and writes the signed area of the polygon they describe, computed with the shoelace formula. Vertices given in counter-clockwise order yield a positive area; clockwise order yields a negative area. The polygon is implicitly closed, so the final vertex need not repeat the first.
Lines that contain no leading number (blank lines, comments, color records, etc.) are silently skipped. A line containing exactly one number is treated as malformed input and aborts the program.
By default coordinates are read from standard input and the area is written to standard output, making cad_parea convenient in a pipeline.
OPTIONS
- -i input
-
Read coordinates from input instead of standard input. A value of - means standard input. May be given only once.
- -o output
-
Write the computed area to output instead of standard output. A value of - means standard output. May be given only once.
- -h, -?
-
Print a usage message and exit.
EXAMPLES
$ cat square.txt
0 0
1 0
1 1
0 1
$ cad_parea -i square.txt
1
The four vertices are listed in counter-clockwise order, so cad_parea reports the positive area 1. Listing them clockwise would instead report -1.
$ printf '0 0\n4 0\n4 3\n0 3\n' | cad_parea -o area.txt
$ cat area.txt
12
Coordinates are streamed in on standard input and the resulting area of the 4x3 rectangle (12) is written to the file area.txt, demonstrating how cad_parea slots into a pipeline that generates vertex lists on the fly.
HINTS
A hole can be accommodated as a clockwise section connected to the periphery by a line segment traced in both directions. Disjoint pieces may likewise be connected by a line segment traced in both directions.
DIAGNOSTICS
A line with a single numeric field is reported as bad input and cad_parea exits with status 2. A degenerate polygon yields an area of 0.
SEE ALSO
brlcad(1), cad_boundp(1)
AUTHOR
BRL-CAD Team
COPYRIGHT
This software is Copyright (c) 1989-2026 by the United States Government as represented by U.S. Army Research Laboratory.
BUG REPORTS
Reports of bugs or problems should be submitted via electronic mail to devs@brlcad.org