Triangle¶
-
class
sknano.core.geometric_regions.
Triangle
(p1=None, p2=None, p3=None)[source] [edit on github][source]¶ Bases:
sknano.core.geometric_regions.Geometric2DRegion
Geometric2DRegion
for a triangle.New in version 0.3.10.
Represents the bounded region with corner points p1=(x1,y1), p2=(x2,y2), and p3=(x3,y3).
Parameters: p2, p3 (p1,) – 2-tuples or Point
class instances specifying theTriangle
corner points p1=(x1,y1), p2=(x2,y2), and p3=(x3,y3).Notes
Triangle
represents a 2D geometric region consisting of all combinations of corner points pi, {λ1p1+λ2p2+λ3p3|λi≥0∧λ1+λ2+λ3=1}.Calling
Triangle
with no parameters is equivalent toTriangle
(p1=[0, 0], p2=[0, 1], p3=[1, 0])
.Attributes
area
Triangle
area.bounding_box
Bounding Cuboid
.center
Alias for centroid
.centroid
Triangle
centroid, (cx,cy).fmtstr
Format string. measure
Alias for area
, which is the measure of a 2D geometric region.ndim
Return the dimensions. p1
Corner point p1=(x1,y1). p2
Corner point p2=(x2,y2). p3
Corner point p3=(x3,y3). pmax
Point
at maximum extent.pmin
Point
at minimum extent.Methods
center_centroid
()Center centroid
on origin.contains
(point)Test region membership of point
inTriangle
.get_points
()Return list of points from GeometricRegion.points
andGeometricRegion.vectors
rotate
(**kwargs)Rotate GeometricRegion
points
andvectors
.todict
()Returns a dict
of theTriangle
constructor parameters.translate
(t[, fix_anchor_points])Translate GeometricRegion
points
andvectors
byVector
t
.Attributes Summary
area
Triangle
area.centroid
Triangle
centroid, (cx,cy).p1
Corner point p1=(x1,y1). p2
Corner point p2=(x2,y2). p3
Corner point p3=(x3,y3). Methods Summary
contains
(point)Test region membership of point
inTriangle
.todict
()Returns a dict
of theTriangle
constructor parameters.Attributes Documentation
-
centroid
¶ Triangle
centroid, (cx,cy).Computed as 2D
Point
(cx,cy) with coordinates:cx=x1+x2+x33cy=y1+y2+y33Returns: 2D Point
of centroid.Return type: Point
-
p1
¶ Corner point p1=(x1,y1).
-
p2
¶ Corner point p2=(x2,y2).
-
p3
¶ Corner point p3=(x3,y3).
Methods Documentation
-
contains
(point)[source] [edit on github][source]¶ Test region membership of
point
inTriangle
.Parameters: point (array_like) – Returns: True
ifpoint
is withinTriangle
,False
, otherwise.Return type: bool
Notes
A point (px,py) is within the bounded region of a triangle with corner points p1=(x1,y1), p2=(x2,y2), and p3=(x3,y3), if the following is true:
(x1−x3)py+(x3−px)y1+(px−x1)y3(y1−y2)x3+(y2−y3)x1+(y3−y1)x2≥0∧(x2−x1)py+(px−x2)y1+(x1−px)y2(y1−y2)x3+(y2−y3)x1+(y3−y1)x2≥0∧(x2−x3)py+(x3−px)y2+(px−x2)y3(y1−y2)x3+(y2−y3)x1+(y3−y1)x2≤0
-