Triangle¶
-
class
sknano.core.geometric_regions.Triangle(p1=None, p2=None, p3=None)[source] [edit on github][source]¶ Bases:
sknano.core.geometric_regions.Geometric2DRegionGeometric2DRegionfor a triangle.New in version 0.3.10.
Represents the bounded region with corner points \(p_1=(x_1,y_1)\), \(p_2=(x_2,y_2)\), and \(p_3=(x_3,y_3)\).
Parameters: p2, p3 (p1,) – 2-tuples or Pointclass instances specifying theTrianglecorner points \(p_1=(x_1,y_1)\), \(p_2=(x_2,y_2)\), and \(p_3=(x_3, y_3)\).Notes
Trianglerepresents a 2D geometric region consisting of all combinations of corner points \(p_i\), \(\left\{\lambda_1 p_1+\lambda_2 p_2 + \lambda_3 p_3| \lambda_i\ge0\land\lambda_1+\lambda_2+\lambda_3=1\right\}\).Calling
Trianglewith no parameters is equivalent toTriangle(p1=[0, 0], p2=[0, 1], p3=[1, 0]).Attributes
areaTrianglearea.bounding_boxBounding Cuboid.centerAlias for centroid.centroidTrianglecentroid, \((c_x, c_y)\).fmtstrFormat string. measureAlias for area, which is the measure of a 2D geometric region.ndimReturn the dimensions. p1Corner point \(p_1=(x_1, y_1)\). p2Corner point \(p_2=(x_2, y_2)\). p3Corner point \(p_3=(x_3, y_3)\). pmaxPointat maximum extent.pminPointat minimum extent.Methods
center_centroid()Center centroidon origin.contains(point)Test region membership of pointinTriangle.get_points()Return list of points from GeometricRegion.pointsandGeometricRegion.vectorsrotate(**kwargs)Rotate GeometricRegionpointsandvectors.todict()Returns a dictof theTriangleconstructor parameters.translate(t[, fix_anchor_points])Translate GeometricRegionpointsandvectorsbyVectort.Attributes Summary
areaTrianglearea.centroidTrianglecentroid, \((c_x, c_y)\).p1Corner point \(p_1=(x_1, y_1)\). p2Corner point \(p_2=(x_2, y_2)\). p3Corner point \(p_3=(x_3, y_3)\). Methods Summary
contains(point)Test region membership of pointinTriangle.todict()Returns a dictof theTriangleconstructor parameters.Attributes Documentation
-
area¶ Trianglearea.Computed as:
\[A = \frac{1}{2}|-x_2 y_1 + x_3 y_1 + x_1 y_2 - x_3 y_2 - x_1 y_3 + x_2 y_3|\]
-
centroid¶ Trianglecentroid, \((c_x, c_y)\).Computed as 2D
Point\((c_x, c_y)\) with coordinates:\[c_x = \frac{x_1 + x_2 + x_3}{3}\]\[c_y = \frac{y_1 + y_2 + y_3}{3}\]Returns: 2D Pointof centroid.Return type: Point
-
p1¶ Corner point \(p_1=(x_1, y_1)\).
-
p2¶ Corner point \(p_2=(x_2, y_2)\).
-
p3¶ Corner point \(p_3=(x_3, y_3)\).
Methods Documentation
-
contains(point)[source] [edit on github][source]¶ Test region membership of
pointinTriangle.Parameters: point (array_like) – Returns: Trueifpointis withinTriangle,False, otherwise.Return type: boolNotes
A point \((p_x, p_y)\) is within the bounded region of a triangle with corner points \(p_1=(x_1, y_1)\), \(p_2=(x_2, y_2)\), and \(p_3=(x_3, y_3)\), if the following is true:
\[\frac{(x_1 - x_3) p_y + (x_3 - p_x) y_1 + (p_x - x_1) y_3}{ (y_1-y_2) x_3 + (y_2 - y_3) x_1 + (y_3 - y_1) x_2}\ge 0\land\]\[\frac{(x_2 - x_1) p_y + (p_x - x_2) y_1 + (x_1 - p_x) y_2}{ (y_1 - y_2) x_3 + (y_2 - y_3) x_1 + (y_3 - y_1) x_2}\ge 0\land\]\[\frac{(x_2 - x_3) p_y + (x_3 - p_x) y_2 + (p_x - x_2) y_3}{ (y_1 - y_2) x_3 + (y_2 - y_3) x_1 + (y_3 - y_1) x_2}\le 0\]
-