Triangles¶
Contruction¶
Read-write attributes¶
-
A: Point2D
-
B: Point2D
-
C: Point2D
Triangle points. They may be replaced by another points, for example:
ABC.A = Point2D(1, 2)
or coordinate may be changed inplace, for example:
ABC.A.y = -2
In either case, the method recompute()
must be called after change(s).
Read only attributes¶
-
area: float
Triangle area.
-
center: Point2D
Triangle center.
-
counterclockwise: bool
Whether triangle is counterclockwise.
Methods¶
-
recompute
(self)¶
Recompute triangle properties (signed area, ...). Must be called when a triangle point is changed, or its coordinate is chanded.
-
includes_point
(self, P, edge_width=0.)¶ Test if the triangle includes (contains) the point \(P\).
If point \(P\) is on one of the edge of triangle, due to numerical accuracy issues, the test may failed.
To solve this issue, if
edge_width_square
is not0
, triangle will be considered to include \(P\) if distance between \(P\) and one of triangle edge is less thanedge_width
(the root square ofedge_width_square
).
-
interpolate
(self, data: double[3], P: Point2D)¶ Interpolate
data
defined on triangle vertices, to a pointP
inside the triangle.
-
plot
(self, style='b-')¶ Plot triangle points using matplotlib
Structures¶
-
CTriangle2D
¶
-
CTriangle2D*
new_triangle2d
()¶ Allocate a new CTriangle2D.
This do not allocate members
A
,B
, andC
.
-
void
del_triangle2d
(CTriangle2D* ctri2d)¶ Delete a CTriangle2D.
This do not delete members
A
,B
, andC
.
-
void
triangle2d_set
(CTriangle2D* ABC, CPoint2D* A, CPoint2D* B, CPoint2D* C)¶ Set triangle points \(A\), \(B\), \(C\).
Computational functions¶
-
bint
triangle2d_includes_point2d
(CTriangle2D* ABC, CPoint2D* P, double edge_width_square)¶ Test if the triangle \(ABC\) includes (contains) the point \(P\).
If point \(P\) is on one of the edge of triangle \(ABC\), due to numerical accuracy issues, the test may failed.
To solve this issue, if
edge_width_square
is not0
, ABC will be considered to include \(P\) if distance between \(P\) and one of \(ABC\) edge is less thanedge_width
(the root square ofedge_width_square
).
-
int
triangle2d_on_edges
(CTriangle2D* ABC, CPoint2D* P, double edge_width_square)¶ Test if point \(P\) is on one of the edge of triangle \(ABC\).
\(P\) will be considered to be on one of the edge of triangle \(ABC\). if distance between \(P\) and one of \(ABC\) edge is less than
edge_width
(the root square ofedge_width_square
).- Returns:
- 0 if \(P\) is on edge \([AB]\),
- 1 if \(P\) is on edge \([BC]\),
- 2 if \(P\) is on edge \([CA]\),
- -2 if \(P\) is not on any edge.
-
double
triangle2d_signed_area
(CTriangle2D* T)¶ Compute the signed area of triangle \(T\).
Triangle area is the absolute value of the signed area.
- If signed area is positive, triangle is counterclockwise.
- If signed area is negative, triangle is clockwise.
- If signed area is zero, triangle is degenerated.
-
double
triangle2d_area
(CTriangle2D* T)¶ Compute the area of triangle \(T\).
-
void
triangle2d_center
(CTriangle2D* T, CPoint2D* C)¶ Compute the center \(C\) of triangle \(T\).
Variable
C
must be already allocated.
-
void
triangle2d_gradx_grady_det
(CTriangle2D* tri, double signed_area, double gradx[3], double grady[3], double det[3])¶ Compute factors for linear interpolation of data defined on triangle vertices \(A\), \(B\) and \(C\) to points included in the triangle.