Skip to main content

Calculate geometric properties of arbitrary 2D polygons

Project description

polygon

Python module to calculate geometric properties of arbitrary 2D polygons:

  • area, centroid (center of mass)
  • second moment of area (bending stiffness of beams)
  • triangles: incircle and circumscribed (outer) circle
  • solid of revolution: volume, surface areas, center of mass
  • check if point is inside or on edge of polygon
  • move, rotate and scale polygon
  • plotting with matplotlib arguments (e.g. color, linestyle, label)

examples:

https://github.com/gerritnowald/polygon/blob/main/examples/examples.ipynb

installation:

pip install polygon-math

creating a polygon object:

from polygon_math import polygon
Vertices = [[x0,y0],[x1,y1],[x2,y2],...]   # 2D-coordinates of vertices
polygon_object = polygon(Vertices)
  • polygon can be open or closed (i.e. first = last vertex)
  • holes can be defined by self-intersecting and opposite order of vertices inside than outside

creating a solid of revolution:

polygon_object = polygon(Vertices, axis)
  • axis = 0: revolution around x-axis
  • axis = 1: revolution around y-axis

attributes of polygon_object (geometrical properties):

v: Vertex index
e: Edge index (next of v)
- .IsClockwise                          Boolean, order of vertices
- .Area
- .Angles[v]                            inner angles
- .EdgesLength[e]
- .EdgesMiddle[xe,ye]                   midpoints of edges
- .CenterMass[x,y]                      centroid / center of mass
- .SecondMomentArea                     [Ixx, Iyy, Ixy], with respect to origin
- triangles:
    - .CenterOuterCircle[x,y]           circumcenter / center of circumsribed (outer) circle
    - .RadiusOuterCircle                radius of circumsribed (outer) circle
    - .CenterInnerCircle[x,y]           center of incircle (inner circle)
    - .RadiusInnerCircle                radius of incircle (inner circle)
- solid of revolution:
    - .RotationVolume
    - .RotationSurfaces[e]
    - .CenterMassCrossSection[r,z]      r radial, z axial, CenterMass[r,z] now relates to solid

methods of polygon_object:

- abs(polygon_object)          returns area or volume of solid of revolution

- plotting (matplotlib optional arguments can be used)
    - .plot()                              contour of polygon
    - .plotCenterMass()
    - .plotCenterEdges()
    - triangles:
        - .plotOutCircle()                 circumscribed (outer) circle
        - .plotIncircle()                  incircle (inner circle)
    - solid of revolution:
        - .plot3d()                        3D wireframe plot of solid
        - .plotRotationAxis()              only keyword arguments
        - .plotCenterMassCrossSection()    for 2D plot

- point testing
    - polygon_object(point), .isPointInside(point)    true, if point [x,y] is inside of polygon (not on the edge)
    - .isPointOnEdge(point)                           true, if point [x,y] is on any edge of polygon

- manipulation (translation, rotation & scaling)
    - polygon_object + [dx,dy] , polygon_object - [dx,dy] , .move([dx,dy])
            translation by distances dx,dy in x,y-direction
    
    - .centerOrigin()
            moves origin of coordinate system to center of mass
                                    
    - .rotate(angle,[cx,cy]) , .rotateClockwise(angle,[cx,cy])
            (counter)-clockwise rotation by angle / °
            with respect to point [cx,cy] (optional, default center of mass)
                                    
    - polygon_object * [fx,fy] , polygon_object / [fx,fy] , .scale([fx,fy],[cx,cy])
            scaling by factors fx, fy in x,y-direction (negative: flip)
            with respect to point [cx,cy] (optional, default center of mass)

requirements

  • numpy >= 1.15.0
  • matplotlib >= 2.0.0

license:

MIT license. You are free to use the code any way you want, without liability or warranty.

Please reference my work if you use it.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

polygon_math-1.3.3.tar.gz (9.2 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

polygon_math-1.3.3-py3-none-any.whl (9.4 kB view details)

Uploaded Python 3

File details

Details for the file polygon_math-1.3.3.tar.gz.

File metadata

  • Download URL: polygon_math-1.3.3.tar.gz
  • Upload date:
  • Size: 9.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.2

File hashes

Hashes for polygon_math-1.3.3.tar.gz
Algorithm Hash digest
SHA256 d3971fd44e9aec3fbe2b7a37b3a87493d5ba79e44005eae860037648bc3791b2
MD5 d37cd355f7c4386acaa0ef43163fcd95
BLAKE2b-256 e0ed45a839fc5ceca0c6b3e1972d62f23aeee42bdbbf9454dfeb74df2c34a0ab

See more details on using hashes here.

File details

Details for the file polygon_math-1.3.3-py3-none-any.whl.

File metadata

  • Download URL: polygon_math-1.3.3-py3-none-any.whl
  • Upload date:
  • Size: 9.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.2

File hashes

Hashes for polygon_math-1.3.3-py3-none-any.whl
Algorithm Hash digest
SHA256 f893b9cbee67779deed98e03c5b7fc50c4452de00e34d0c40260ca4521294368
MD5 25371e35e8baa39b80cf809001c2aa05
BLAKE2b-256 53454d49e660100f061a5987e95946730f6a314699ae17e29b63355ee538d253

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page