1// This file is part of SmallBASIC
2//
3// SmallBASIC LIBRARY - extra geometry algorithms
4//
5// This program is distributed under the terms of the GPL v2.0 or later
6// Download the GNU Public License (GPL) from www.gnu.org
7//
8// Copyright(C) 2000 Nicholas Christopoulos
9
10/**
11 * @defgroup math Mathematics
12 */
13
14#if !defined(_blib_geom_h)
15#define _blib_geom_h
16
17#include "common/sys.h"
18#include "common/pproc.h"
19
20/**
21 * @ingroup math
22 *
23 * returns the length of a line-segment
24 *
25 * @param Ax the point A
26 * @param Ay the point A
27 * @param Ax the point B
28 * @param Ay the point B
29 * @return the length of a line-segment
30 */
31double geo_seglen(double Ax, double Ay, double Bx, double By);
32
33/**
34 * @ingroup math
35 *
36 * distance of point C from line (A,B)
37 */
38double geo_distfromline(double Ax, double Ay, double Bx, double By, double Cx, double Cy);
39
40/**
41 * @ingroup math
42 *
43 * distance of point C from line segment (A->B)
44 */
45double geo_distfromseg(double Ax, double Ay, double Bx, double By, double Cx, double Cy);
46
47/**
48 * @ingroup math
49 *
50 * returns the angle of two vectors
51 *
52 * @param type kwSEGCOS or kwSEGSIN, return the angle's cosine or the sine
53 * @param Adx the first vector (dx)
54 * @param Ady the first vector (dy)
55 * @param Bdx the second vector (dx)
56 * @param Bdy the second vector (dy)
57 * @return the cosine or the sine of two vectors
58 */
59double geo_segangle(int type, double Adx, double Ady, double Bdx, double Bdy);
60
61/**
62 * @ingroup math
63 *
64 * Calculates the centroid (xCentroid, yCentroid) and area
65 * of a polygon, given its vertices (x[0], y[0]) ... (x[n-1], y[n-1]).
66 * It is assumed that the contour is closed, i.e., that the vertex following
67 * (x[n-1], y[n-1]) is (x[0], y[0]). The algebraic sign of the area is
68 * positive for counterclockwise ordering of vertices in x-y plane;
69 * otherwise negative.
70 *
71 * Returned values: 0 for normal execution; 1 if the polygon is
72 * degenerate (number of vertices < 3); and 2 if area = 0 (and the
73 * centroid is undefined).
74 */
75int geo_polycentroid(pt_t * poly, int n, var_num_t *xCentroid, var_num_t *yCentroid, var_num_t *area);
76
77#endif
78