def test_four_cells(self): """ 25 +-----+-----+-----+-----+ | | | | | | | B | | | | | /|\| | | |8 | / | \ | 11| 20 +-----+/--|-+\----+-----+ | / | | \ | | | /| 1|0| \ | | | C-----E-----A | | Triangles Center |4 \| 2|3| / | 7| 0 ABE (12, 19) 15 +-----\---|-+-/---+-----+ 1 BCE ( 8, 19) | |\ | |/ | | 2 CDE ( 8, 15) | | \ | / | | 3 DAE (12, 15) | | \|/| | | |0 | D | | 3| 10 +-----+-----+-----+-----+ 0 6 12 18 24 """ A = ga.Point2D(16, 17, 0) B = ga.Point2D(10, 23, 1) C = ga.Point2D(4, 17, 2) D = ga.Point2D(10, 11, 3) E = ga.Point2D(10, 17, 4) points = [A, B, C, D, E] x = np.asarray([P.x for P in points]) y = np.asarray([P.y for P in points]) triangles = [(A, B, E), (B, C, E), (C, D, E), (D, A, E)] trivtx = np.asarray([[P.index for P in vertices] for vertices in triangles], dtype='int32') TG = ga.Triangulation2D(x, y, trivtx) grid = ga.Grid2D(0, 24, 4, 10, 25, 3) bounds = np.zeros((4, 4), dtype='int32') ga.build_triangle_to_cell(bounds, TG, grid, 0.01) assert_equal(bounds, [[1, 3, 1, 3], [0, 2, 1, 3], [0, 2, 0, 2], [1, 3, 0, 2]])
def test_points_out(self): """ E 15 28----------29----------30----------31 |\ /|\ /|\ /| | \ 33 / | \ 36 / | \ 39 / | 14 | \ / | \ / | \ / | |32 \ / 34|35 \ / 37|38 \ / 40| | \ / | \ / | \ / | 13 21----22----23----24----25----26----27 |28 / |29 / | A B | \ 30| \ 31| | / 12| / 13| | 14\ | 15\ | F 12 14----15----16----17----18----19----20 D |22 / |23 / |24 / | \ 25| \ 26| \ 27| | / 6 | / 7 | / 8 |9 \ |10 \ |11 \ | 11 7-----8-----9----10----11----12----13 |16 / |17 / |18 / | \ 19| \ 20| \ 21| | / 0 | / 1 | / 2 |3 \ |4 \ |5 \ | 10 0-----1-----2-----3-----4-----5-----6 0 1 2 3 4 5 6 C """ # Points out of the domain A = ga.Point2D(2.5, 12.5) B = ga.Point2D(3.5, 12.5) C = ga.Point2D(3, 9) D = ga.Point2D(-1, 12) E = ga.Point2D(3, 16) F = ga.Point2D(7, 12) points = [A, B, C, D, E, F] NP = len(points) x = np.array([P.x for P in points]) y = np.array([P.x for P in points]) locator = ga.TriangulationLocator(HOLE.triangulation) triangles = locator.search_points(x, y) assert_equal(triangles, np.full(NP, fill_value=-1, dtype='int32'))
""" ================================= Segment2D two intersection ================================= Create segment, and find their intersections """ import matplotlib.pylab as plt import geomalgo as ga # Create segment AB. A = ga.Point2D(2, 1, name='A') B = ga.Point2D(6, 3, name='B') AB = ga.Segment2D(A, B) # Create segment CD. C = ga.Point2D(4, 2, name='C') D = ga.Point2D(8, 4, name='D') CD = ga.Segment2D(C, D) # Plot the points and the segments. for p in [A, B, C, D]: p.plot() AB.plot() CD.plot() # Compute intersection X, Y = AB.intersect_segment(CD)
""" ================================= Point2D ================================= Create two 2-dimensional points, and compute distance between them. """ import matplotlib.pylab as plt import geomalgo as ga # Create two points. A = ga.Point2D(2, 1, name='A') B = ga.Point2D(6, 4, name='B') # Plot the points. A.plot() B.plot() # Compute distance. print("Distance : {}".format(A.distance(B))) # Adjust the plot. plt.axis('scaled') plt.xlim(1, 7) plt.ylim(0, 5) plt.grid() plt.show()
""" ================================= Segment2D intersection ================================= Create segment, and find their intersections """ import matplotlib.pylab as plt import geomalgo as ga # Create segment AB. A = ga.Point2D(2, 1, name='A') B = ga.Point2D(6, 4, name='B') AB = ga.Segment2D(A, B) # Create segment CD. C = ga.Point2D(5, 2, name='C') D = ga.Point2D(3, 3, name='D') CD = ga.Segment2D(C, D) # Plot the points and the segments. for p in [A, B, C, D]: p.plot() AB.plot() CD.plot() # Compute first intersection point. X, Y = AB.intersect_segment(CD) X.name = 'X'
""" ================================= Triangle2D ================================= Create a triangle """ import numpy as np import matplotlib.pylab as plt import geomalgo as ga # Create segment XY. X = ga.Point2D(2, 1, name='X') Y = ga.Point2D(5, 4, name='Y') Z = ga.Point2D(5, 1, name='Z') XYZ = ga.Triangle2D(X, Y, Z) # Plot triangle. X.plot() Y.plot() Z.plot(offset=(0.2, 0)) XYZ.plot() # Retrive points. print('First triangle point: ', XYZ.A) print('Second triangle point: ', XYZ.B) print('Third triangle point: ', XYZ.C) # Retrive various information.
""" ================================= Segment2D ================================= Create a segment """ import matplotlib.pylab as plt import geomalgo as ga # Create segment XY. X = ga.Point2D(2, 1, name='X') Y = ga.Point2D(5, 4, name='Y') XY = ga.Segment2D(X, Y) # Plot segment. X.plot() Y.plot() XY.plot() # Retrieve points. print('Segment first point:', XY.A) print('Segment second point:', XY.B) # Use parametric coordinates. print('Point at paraemtric coordinate 1/3:', XY.at(1/3)) print('Point (3, 2) is at paraemtric coordinate:', XY.where(ga.Point2D(3, 2))) # Length and recompute.