In [3]:
import polygonmeshtools as pmt
%matplotlib inline
In [2]:
for obj in dir(pmt):
if hasattr(eval("pmt." + obj), '__call__'):
print obj
CartesianCoords and PolarCoords are classes that were designed to be used in-house for the conversion between Cartesian and Polar coordinates. You just need to initialise the object with some coordinates, and then it is easy to extract the relevant information.
3D coordinates are possible, but the z-coordinate has a default value of 0.
In [3]:
cc = pmt.CartesianCoords(5,5)
print("2D\n")
print("x-coordinate: {}".format(cc.x))
print("y-coordinate: {}".format(cc.y))
print("radial: {}".format(cc.r))
print("azimuth: {}".format(cc.a))
cc3D = pmt.CartesianCoords(1,2,3)
print("\n3D\n")
print("x-coordinate: {}".format(cc3D.x))
print("y-coordinate: {}".format(cc3D.y))
print("z-coordinate: {}".format(cc3D.z))
print("radial: {}".format(cc3D.r))
print("azimuth: {}".format(cc3D.a))
print("height: {}".format(cc3D.h))
pmt.PolarCoords works in exactly the same way, but instead you initialise it with polar coordinates (radius, azimuth and height (optional), respectively) and the cartesian ones can be extracted as above.
In [4]:
print(pmt.in_poly.__doc__)
Takes three arguments by default:
Optional arguments are:
Examples below:
In [5]:
pmt.in_poly(x=5, y=30, n=3, r=40, plot=True)
Out[5]:
In [6]:
pmt.in_poly(x=5, y=30, n=3, r=40) # No graph will be generated, more useful for use within other functions
Out[6]:
In [7]:
pmt.in_poly(x=0, y=10, n=6, r=20, plot=True) # Dot changes colour to green when inside the polygon
Out[7]:
In [8]:
import numpy as np
pmt.in_poly(x=-10, y=-25, n=6, r=20, rotation=np.pi/6, translate=(5,-20), plot=True) # Rotation and translation
Out[8]:
And of course, as n becomes large, the polygon tends to a circle:
In [9]:
pmt.in_poly(x=3, y=5, n=100, r=10, plot=True)
Out[9]:
In [10]:
print(pmt.plot_circular_fidi_mesh.__doc__)
Only has one default argument:
Optional arguments:
y_spacing, the height of the mesh elements. Default y_spacing=2 (only integers are currently supported for x- and y-spacing.)
centre_mesh, outlined in the documentation above. Default centre_mesh='auto'
In [11]:
pmt.plot_circular_fidi_mesh(diameter=60)
In [12]:
pmt.plot_circular_fidi_mesh(diameter=60, x_spacing=2, y_spacing=2, centre_mesh=True)
# Note the effect of centre_mesh=True. In the previous plot, the element boundaries are aligned with 0 on the x- and y-axes.
# In this case, centring the mesh has the effect of producing a mesh that is slightly wider than desired, shown below.
In [13]:
pmt.plot_circular_fidi_mesh(diameter=30, x_spacing=1, y_spacing=2, show_axes=False, show_title=False)
# Flexible element sizes. Toggling axes and title can make for prettier (albeit less informative) pictures.
In [14]:
print(pmt.plot_poly_fidi_mesh.__doc__)
Requires two arguments:
Optional arguments:
show_title
(All of the above have the same function as in plot_circular_fidi_mesh, and below, like in_poly)
In [15]:
pmt.plot_poly_fidi_mesh(diameter=50, n=5, x_spacing=1, y_spacing=1, rotation=np.pi/10)
In [16]:
print(pmt.find_circumradius.__doc__)
If you need to specify the side length, or the distance from the circumcentre to the middle of one of the faces, this function will convert that value to the circumradius (not diameter!) that would give the correct side length or apothem.
In [17]:
pmt.find_circumradius(n=3, side=10)
Out[17]:
Using this in combination with plot_poly_fidi_mesh:
In [18]:
d1 = 2*pmt.find_circumradius(n=3, side=40)
pmt.plot_poly_fidi_mesh(diameter=d1, n=3, x_spacing=1, y_spacing=1)
# It can be seen on the y-axis that the side has a length of 40, as desired.
In [19]:
d2 = 2*pmt.find_circumradius(n=5, apothem=20)
pmt.plot_poly_fidi_mesh(diameter=d2, n=5, x_spacing=1, y_spacing=1)
# The circumcentre lies at (0,0), and the leftmost side is in line with x=-20
In [19]: