irfpy.util.triangle2d¶
Triangle in 2D.
Code author: Yoshifumi Futaana
Triangle, defined by x-y plane, is implemented.
Triangle2D provides the main functionality.
create_triangle() will create a Triangle2D object.
Triangle P0=(1,3), P1=(3,3), P2=(1,8) is created by
>>> tri = create_triangle([1, 3], [3, 3], [1, 8])
>>> print(tri.get_area()) # Calculate the area.
5.0
>>> print(tri.isinside([2, 4])) # P=(2,4) is inside the triangle
True
>>> print(tri.isinside([1, 2])) # P=(1,2) is on the triangle
True
>>> print(tri.isinside([1, 2], bound=False)) # P=(1,2) is on the triangle
False
-
class
irfpy.util.triangle2d.Triangle2D(xlist, ylist)[source]¶ Bases:
objectCreate 2D triangle.
-
p0= None¶ The first point
-
p1= None¶ The second point
-
p2= None¶ The third point
-
get_area()[source]¶ Return the area of the triangle.
Triangle, P0 is origin, P1 is x=1, P2 is y=1. >>> tri = Triangle2D([1, 0, 0], [0, 1, 0]) >>> print(tri.get_area()) 0.5
-
isinside(point, bound=True)[source]¶ Return true if the given point is inside or on the bound of the triangle
>>> tri = Triangle2D([0.1, 1, 0.1], [0.1, 0.1, 1]) >>> tri.isinside([0.1, 0.1]) # It is on the bound. True >>> tri.isinside([0.1, 0.1], bound=False) # It is on the bound. False
>>> tri.isinside([0.3, 0.3]) True
-
-
class
irfpy.util.triangle2d.Polygon2D(xs, ys)[source]¶ Bases:
objectPolygon, extending
Triangle2Dusing triangulation.>>> poly = Polygon2D([-1, 0, 1, 0], [0, -1, 0, 1]) >>> print(poly.isinside([0, 0])) # Is (0,0) inside? Yes. True
-
triangulate()[source]¶ Triangulation.
- Returns
A set of
Triangle2D
Indeed, this is not yet fully debugged.
-