microstructpy.geometry.Circle¶
-
class
microstructpy.geometry.
Circle
(**kwargs)[source]¶ Bases:
microstructpy.geometry.n_sphere.NSphere
A 2D circle.
This class represents a two-dimensional circle. It is defined by a center point and size parameter, which can be either radius or diameter.
Without parameters, this returns a unit circle centered on the origin.
- Parameters
r (float) – (optional) The radius of the circle. Defaults to 1.
center (list) – (optional) The coordinates of the center. Defaults to (0, 0).
diameter – (optional) Alias for
2*r
.radius – (optional) Alias for
r
.d – (optional) Alias for
2*r
.size – (optional) Alias for
2*r
.position – (optional) Alias for
center
.
-
approximate
()¶ Approximate the n-sphere with itself
Other geometries can be approximated by a set of circles or spheres. For the n-sphere, this approximation is exact.
- Returns
A list containing [(x, y, z, …, r)]
- Return type
-
classmethod
area_expectation
(**kwargs)[source]¶ Expected value of area.
This function computes the expected value for the area of a circle. The keyword arguments are the same as the class parameters. The values can be constants (ints or floats), or a distribution from the SciPy
scipy.stats
module.The expected value is computed by the following formula:
\[\mathbb{E}[A] = \pi \mathbb{E}[R^2] = \pi (\mu_R^2 + \sigma_R^2)\]For example:
>>> from microstructpy.geometry import Circle >>> Circle.area_expectation(r=1) 3.141592653589793 >>> from scipy.stats import norm >>> Circle.area_expectation(r=norm(1, 1)) 6.283185307179586
-
classmethod
best_fit
(points)¶ Find n-sphere of best fit for set of points.
This function takes a list of points and computes an n-sphere of best fit, in an algebraic sense. This method was developed using the a published writeup, which was extended from 2D to ND. 1
- Parameters
points (list, numpy.ndarray) – List of points to fit.
- Returns
An instance of the class that fits the points.
- Return type
- 1
Circle fitting writup by Randy Bullock, https://dtcenter.org/met/users/docs/write_ups/circle_fit.pdf
-
plot
(**kwargs)[source]¶ Plot the circle.
This function adds a
matplotlib.patches.Circle
to the current axes. The keyword arguments are passed through to the circle patch.- Parameters
**kwargs (dict) – Keyword arguments for matplotlib.
-
reflect
(points)¶ Reflect points across surface.
This function reflects a point or set of points across the surface of the n-sphere. Points at the center of the n-sphere are not reflected.
- Parameters
points (list or numpy.ndarray) – Points to reflect.
- Returns
Reflected points.
- Return type
-
within
(points)¶ Test if points are within n-sphere.
This function tests whether a point or set of points are within the n-sphere. For the set of points, a list of booleans is returned to indicate which points are within the n-sphere.
- Parameters
points (list or numpy.ndarray) – Point or list of points.
- Returns
Set to True for points in geometry.
- Return type