freegsnke.polygons module
Routines for calculating intersection or other geometric calculations with polygons (e.g. walls, flux surface approximations)
Copyright 2019 Ben Dudson, University of York. Email: benjamin.dudson@york.ac.uk
This file is part of FreeGSNKE.
FreeGSNKE is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
FreeGSNKE is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public License along with FreeGSNKE. If not, see <http://www.gnu.org/licenses/>.
- freegsnke.polygons.area(polygon: list[tuple[float, float]]) float[source]
Calculate the signed area of a polygon.
Positive for a clockwise polygon, negative for an anticlockwise one.
- Parameters:
polygon (list[tuple[float, float]]) – Vertices
[(r1, z1), (r2, z2), ...].- Returns:
Signed area of the polygon.
- Return type:
float
- freegsnke.polygons.clockwise(polygon: list[tuple[float, float]]) bool[source]
Detect whether a polygon is clockwise or anti-clockwise.
- Parameters:
polygon (list[tuple[float, float]]) – Vertices
[(r1, z1), (r2, z2), ...].- Returns:
True if the polygon is clockwise, False if anticlockwise.
- Return type:
bool
- freegsnke.polygons.intersect(r1: list[float], z1: list[float], r2: list[float], z2: list[float], closed1: bool = True, closed2: bool = True) bool[source]
Test if two polylines (or polygons) intersect.
The polylines consist of the (r1, z1) and (r2, z2) line segments.
- Parameters:
r1 (list[float]) – R and Z coordinates of the vertices of the first polyline.
z1 (list[float]) – R and Z coordinates of the vertices of the first polyline.
r2 (list[float]) – R and Z coordinates of the vertices of the second polyline.
z2 (list[float]) – R and Z coordinates of the vertices of the second polyline.
closed1 (bool, optional) – If True, the last vertex of the first polyline joins the first.
closed2 (bool, optional) – If True, the last vertex of the second polyline joins the first.
- Returns:
True if any pair of segments intersect, False otherwise.
- Return type:
bool
- freegsnke.polygons.triangulate(polygon: list[tuple[float, float]]) list[list[tuple[float, float]]][source]
Use the ear clipping method to turn an arbitrary polygon into triangles.
- Parameters:
polygon (list[tuple[float, float]]) – Vertices
[(r1, z1), (r2, z2), ...](at least three).- Returns:
Triangles, each a list of three
(r, z)vertices.- Return type:
list[list[tuple[float, float]]]