1 |
/*
|
2 |
* This file is a part of Poly2Tri-C
|
3 |
* (c) Barak Itkin <lightningismyname@gmail.com>
|
4 |
* http://code.google.com/p/poly2tri-c/
|
5 |
*
|
6 |
* All rights reserved.
|
7 |
*
|
8 |
* Redistribution and use in source and binary forms, with or without modification,
|
9 |
* are permitted provided that the following conditions are met:
|
10 |
*
|
11 |
* * Redistributions of source code must retain the above copyright notice,
|
12 |
* this list of conditions and the following disclaimer.
|
13 |
* * Redistributions in binary form must reproduce the above copyright notice,
|
14 |
* this list of conditions and the following disclaimer in the documentation
|
15 |
* and/or other materials provided with the distribution.
|
16 |
* * Neither the name of Poly2Tri nor the names of its contributors may be
|
17 |
* used to endorse or promote products derived from this software without specific
|
18 |
* prior written permission.
|
19 |
*
|
20 |
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
21 |
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
22 |
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
23 |
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
|
24 |
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
25 |
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
26 |
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
27 |
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
28 |
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
29 |
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
30 |
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
31 |
*/
|
32 |
|
33 |
#ifndef __P2TC_REFINE_MATH_H__
|
34 |
#define __P2TC_REFINE_MATH_H__
|
35 |
|
36 |
#include <glib.h>
|
37 |
#include "vector2.h"
|
38 |
#include "circle.h"
|
39 |
|
40 |
gdouble p2tr_math_length_sq (gdouble x1,
|
41 |
gdouble y1,
|
42 |
gdouble x2,
|
43 |
gdouble y2);
|
44 |
|
45 |
gdouble p2tr_math_length_sq2 (const P2trVector2 *pt1,
|
46 |
const P2trVector2 *pt2);
|
47 |
|
48 |
|
49 |
/**
|
50 |
* Find the circumscribing circle of a triangle defined by the given
|
51 |
* points.
|
52 |
* @param[in] A The first vertex of the triangle
|
53 |
* @param[in] B The second vertex of the triangle
|
54 |
* @param[in] C The third vertex of the triangle
|
55 |
* @param[out] circle The circumscribing circle of the triangle
|
56 |
*/
|
57 |
void p2tr_math_triangle_circumcircle (const P2trVector2 *A,
|
58 |
const P2trVector2 *B,
|
59 |
const P2trVector2 *C,
|
60 |
P2trCircle *circle);
|
61 |
|
62 |
typedef enum
|
63 |
{
|
64 |
P2TR_INTRIANGLE_OUT = -1,
|
65 |
P2TR_INTRIANGLE_ON = 0,
|
66 |
P2TR_INTRIANGLE_IN = 1
|
67 |
} P2trInTriangle;
|
68 |
|
69 |
/**
|
70 |
* Return the barycentric coordinates of a point inside a triangle. This
|
71 |
* means that the computation returns @ref u and @ref v so that the
|
72 |
* following equation is satisfied:
|
73 |
* {{{ AP = u * AB + v * AC }}}
|
74 |
*
|
75 |
* @param[in] A The first point of the triangle
|
76 |
* @param[in] B The second point of the triangle
|
77 |
* @param[in] C The third point of the triangle
|
78 |
* @param[in] P The point whose barycentric coordinates should be
|
79 |
* computed
|
80 |
* @param[out] u The first barycentric coordinate
|
81 |
* @param[out] v The second barycentric coordinate
|
82 |
*/
|
83 |
void p2tr_math_triangle_barcycentric (const P2trVector2 *A,
|
84 |
const P2trVector2 *B,
|
85 |
const P2trVector2 *C,
|
86 |
const P2trVector2 *P,
|
87 |
gdouble *u,
|
88 |
gdouble *v);
|
89 |
|
90 |
P2trInTriangle p2tr_math_intriangle (const P2trVector2 *A,
|
91 |
const P2trVector2 *B,
|
92 |
const P2trVector2 *C,
|
93 |
const P2trVector2 *P);
|
94 |
|
95 |
P2trInTriangle p2tr_math_intriangle2 (const P2trVector2 *A,
|
96 |
const P2trVector2 *B,
|
97 |
const P2trVector2 *C,
|
98 |
const P2trVector2 *P,
|
99 |
gdouble *u,
|
100 |
gdouble *v);
|
101 |
|
102 |
typedef enum
|
103 |
{
|
104 |
P2TR_ORIENTATION_CW = -1,
|
105 |
P2TR_ORIENTATION_LINEAR = 0,
|
106 |
P2TR_ORIENTATION_CCW = 1
|
107 |
} P2trOrientation;
|
108 |
|
109 |
P2trOrientation p2tr_math_orient2d (const P2trVector2 *A,
|
110 |
const P2trVector2 *B,
|
111 |
const P2trVector2 *C);
|
112 |
|
113 |
typedef enum
|
114 |
{
|
115 |
P2TR_INCIRCLE_IN,
|
116 |
P2TR_INCIRCLE_ON,
|
117 |
P2TR_INCIRCLE_OUT
|
118 |
} P2trInCircle;
|
119 |
|
120 |
P2trInCircle p2tr_math_incircle (const P2trVector2 *A,
|
121 |
const P2trVector2 *B,
|
122 |
const P2trVector2 *C,
|
123 |
const P2trVector2 *D);
|
124 |
|
125 |
gboolean p2tr_math_diametral_circle_contains (const P2trVector2 *X,
|
126 |
const P2trVector2 *Y,
|
127 |
const P2trVector2 *W);
|
128 |
|
129 |
gboolean p2tr_math_diametral_lens_contains (const P2trVector2 *X,
|
130 |
const P2trVector2 *Y,
|
131 |
const P2trVector2 *W);
|
132 |
#endif
|