The geometry module for SymPy allows one to create two-dimensional geometrical entities, such as lines and circles, and query for information about these entities. This could include asking the area of an ellipse, checking for collinearity of a set of points, or finding the intersection between two lines. The primary use case of the module involves entities with numerical values, but it is possible to also use symbolic representations.
The following entities are currently available in the geometry module:
Most of the work one will do will be through the properties and methods of these entities, but several global methods exist:
For a full API listing and an explanation of the methods and their return values please see the list of classes at the end of this document.
The following Python session gives one an idea of how to work with some of the geometry module.
>>> from sympy import *
>>> from sympy.geometry import *
>>> x = Point(0, 0)
>>> y = Point(1, 1)
>>> z = Point(2, 2)
>>> zp = Point(1, 0)
>>> Point.is_collinear(x, y, z)
True
>>> Point.is_collinear(x, y, zp)
False
>>> t = Triangle(zp, y, x)
>>> t.area
1/2
>>> t.medians[x]
Segment(Point(0, 0), Point(1, 1/2))
>>> Segment(Point(1, S(1)/2), Point(0, 0))
Segment(Point(0, 0), Point(1, 1/2))
>>> m = t.medians
>>> intersection(m[x], m[y], m[zp])
[Point(2/3, 1/3)]
>>> c = Circle(x, 5)
>>> l = Line(Point(5, -5), Point(5, 5))
>>> c.is_tangent(l) # is l tangent to c?
True
>>> l = Line(x, y)
>>> c.is_tangent(l) # is l tangent to c?
False
>>> intersection(c, l)
[Point(-5*sqrt(2)/2, -5*sqrt(2)/2), Point(5*sqrt(2)/2, 5*sqrt(2)/2)]
>>> from sympy import symbols
>>> from sympy.geometry import Point, Triangle, intersection
>>> a, b = symbols("a,b", positive=True)
>>> x = Point(0, 0)
>>> y = Point(a, 0)
>>> z = Point(2*a, b)
>>> t = Triangle(x, y, z)
>>> t.area
a*b/2
>>> t.medians[x]
Segment(Point(0, 0), Point(3*a/2, b/2))
>>> intersection(t.medians[x], t.medians[y], t.medians[z])
[Point(a, b/3)]
From Wikipedia ([WikiPappus]):
Given one set of collinear points \(A\), \(B\), \(C\), and another set of collinear points \(a\), \(b\), \(c\), then the intersection points \(X\), \(Y\), \(Z\) of line pairs \(Ab\) and \(aB\), \(Ac\) and \(aC\), \(Bc\) and \(bC\) are collinear.
>>> from sympy import *
>>> from sympy.geometry import *
>>>
>>> l1 = Line(Point(0, 0), Point(5, 6))
>>> l2 = Line(Point(0, 0), Point(2, -2))
>>>
>>> def subs_point(l, val):
... """Take an arbitrary point and make it a fixed point."""
... t = Symbol('t', real=True)
... ap = l.arbitrary_point()
... return Point(ap.x.subs(t, val), ap.y.subs(t, val))
...
>>> p11 = subs_point(l1, 5)
>>> p12 = subs_point(l1, 6)
>>> p13 = subs_point(l1, 11)
>>>
>>> p21 = subs_point(l2, -1)
>>> p22 = subs_point(l2, 2)
>>> p23 = subs_point(l2, 13)
>>>
>>> ll1 = Line(p11, p22)
>>> ll2 = Line(p11, p23)
>>> ll3 = Line(p12, p21)
>>> ll4 = Line(p12, p23)
>>> ll5 = Line(p13, p21)
>>> ll6 = Line(p13, p22)
>>>
>>> pp1 = intersection(ll1, ll3)[0]
>>> pp2 = intersection(ll2, ll5)[0]
>>> pp3 = intersection(ll4, ll6)[0]
>>>
>>> Point.is_collinear(pp1, pp2, pp3)
True
[WikiPappus] | “Pappus’s Hexagon Theorem” Wikipedia, the Free Encyclopedia. Web. 26 Apr. 2013. <http://en.wikipedia.org/wiki/Pappus’s_hexagon_theorem> |
When one deals with symbolic entities, it often happens that an assertion cannot be guaranteed. For example, consider the following code:
>>> from sympy import *
>>> from sympy.geometry import *
>>> x,y,z = map(Symbol, 'xyz')
>>> p1,p2,p3 = Point(x, y), Point(y, z), Point(2*x*y, y)
>>> Point.is_collinear(p1, p2, p3)
False
Even though the result is currently False, this is not always true. If the quantity \(z - y - 2*y*z + 2*y**2 == 0\) then the points will be collinear. It would be really nice to inform the user of this because such a quantity may be useful to a user for further calculation and, at the very least, being nice to know. This could be potentially done by returning an object (e.g., GeometryResult) that the user could use. This actually would not involve an extensive amount of work.
Currently there are no plans for extending the module to three dimensions, but it certainly would be a good addition. This would probably involve a fair amount of work since many of the algorithms used are specific to two dimensions.
The plotting module is capable of plotting geometric entities. See Plotting Geometric Entities in the plotting module entry.
The base class for all geometrical entities.
This class doesn’t represent any particular geometric entity, it only provides the implementation of some methods common to all subclasses.
Return True if o is inside (not on or outside) the boundaries of self.
The object will be decomposed into Points and individual Entities need only define an encloses_point method for their class.
See also
sympy.geometry.ellipse.Ellipse.encloses_point, sympy.geometry.polygon.Polygon.encloses_point
Examples
>>> from sympy import RegularPolygon, Point, Polygon
>>> t = Polygon(*RegularPolygon(Point(0, 0), 1, 3).vertices)
>>> t2 = Polygon(*RegularPolygon(Point(0, 0), 2, 3).vertices)
>>> t2.encloses(t)
True
>>> t.encloses(t2)
False
Returns a list of all of the intersections of self with o.
See also
Notes
An entity is not required to implement this method.
If two different types of entities can intersect, the item with higher index in ordering_of_classes should implement intersections with anything having a lower index.
Is this geometrical entity similar to another geometrical entity?
Two entities are similar if a uniform scaling (enlarging or shrinking) of one of the entities will allow one to obtain the other.
See also
Notes
This method is not intended to be used directly but rather through the \(are_similar\) function found in util.py. An entity is not required to implement this method. If two different types of entities can be similar, it is only required that one of them be able to determine this.
Rotate angle radians counterclockwise about Point pt.
The default pt is the origin, Point(0, 0)
Examples
>>> from sympy import Point, RegularPolygon, Polygon, pi
>>> t = Polygon(*RegularPolygon(Point(0, 0), 1, 3).vertices)
>>> t # vertex on x axis
Triangle(Point(1, 0), Point(-1/2, sqrt(3)/2), Point(-1/2, -sqrt(3)/2))
>>> t.rotate(pi/2) # vertex on y axis now
Triangle(Point(0, 1), Point(-sqrt(3)/2, -1/2), Point(sqrt(3)/2, -1/2))
Scale the object by multiplying the x,y-coordinates by x and y.
If pt is given, the scaling is done relative to that point; the object is shifted by -pt, scaled, and shifted by pt.
Examples
>>> from sympy import RegularPolygon, Point, Polygon
>>> t = Polygon(*RegularPolygon(Point(0, 0), 1, 3).vertices)
>>> t
Triangle(Point(1, 0), Point(-1/2, sqrt(3)/2), Point(-1/2, -sqrt(3)/2))
>>> t.scale(2)
Triangle(Point(2, 0), Point(-1, sqrt(3)/2), Point(-1, -sqrt(3)/2))
>>> t.scale(2,2)
Triangle(Point(2, 0), Point(-1, sqrt(3)), Point(-1, -sqrt(3)))
Shift the object by adding to the x,y-coordinates the values x and y.
Examples
>>> from sympy import RegularPolygon, Point, Polygon
>>> t = Polygon(*RegularPolygon(Point(0, 0), 1, 3).vertices)
>>> t
Triangle(Point(1, 0), Point(-1/2, sqrt(3)/2), Point(-1/2, -sqrt(3)/2))
>>> t.translate(2)
Triangle(Point(3, 0), Point(3/2, sqrt(3)/2), Point(3/2, -sqrt(3)/2))
>>> t.translate(2, 2)
Triangle(Point(3, 2), Point(3/2, sqrt(3)/2 + 2),
Point(3/2, -sqrt(3)/2 + 2))
The intersection of a collection of GeometryEntity instances.
Parameters: | entities : sequence of GeometryEntity |
---|---|
Returns: | intersection : list of GeometryEntity |
Raises: | NotImplementedError :
|
Notes
The intersection of any geometrical entity with itself should return a list with one item: the entity in question. An intersection requires two or more entities. If only a single entity is given then the function will return an empty list. It is possible for \(intersection\) to miss intersections that one knows exists because the required quantities were not fully simplified internally. Reals should be converted to Rationals, e.g. Rational(str(real_num)) or else failures due to floating point issues may result.
Examples
>>> from sympy.geometry import Point, Line, Circle, intersection
>>> p1, p2, p3 = Point(0, 0), Point(1, 1), Point(-1, 5)
>>> l1, l2 = Line(p1, p2), Line(p3, p2)
>>> c = Circle(p2, 1)
>>> intersection(l1, p2)
[Point(1, 1)]
>>> intersection(l1, l2)
[Point(1, 1)]
>>> intersection(c, p2)
[]
>>> intersection(c, Point(1, 0))
[Point(1, 0)]
>>> intersection(c, l2)
[Point(-sqrt(5)/5 + 1, 2*sqrt(5)/5 + 1),
Point(sqrt(5)/5 + 1, -2*sqrt(5)/5 + 1)]
The convex hull surrounding the Points contained in the list of entities.
Parameters: | args : a collection of Points, Segments and/or Polygons |
---|---|
Returns: | convex_hull : Polygon |
Notes
This can only be performed on a set of non-symbolic points.
References
[1] http://en.wikipedia.org/wiki/Graham_scan
[2] Andrew’s Monotone Chain Algorithm (A.M. Andrew, “Another Efficient Algorithm for Convex Hulls in Two Dimensions”, 1979) http://softsurfer.com/Archive/algorithm_0109/algorithm_0109.htm
Examples
>>> from sympy.geometry import Point, convex_hull
>>> points = [(1,1), (1,2), (3,1), (-5,2), (15,4)]
>>> convex_hull(*points)
Polygon(Point(-5, 2), Point(1, 1), Point(3, 1), Point(15, 4))
Are two geometrical entities similar.
Can one geometrical entity be uniformly scaled to the other?
Parameters: | e1 : GeometryEntity e2 : GeometryEntity |
---|---|
Returns: | are_similar : boolean |
Raises: | GeometryError :
|
Notes
If the two objects are equal then they are similar.
Examples
>>> from sympy import Point, Circle, Triangle, are_similar
>>> c1, c2 = Circle(Point(0, 0), 4), Circle(Point(1, 4), 3)
>>> t1 = Triangle(Point(0, 0), Point(1, 0), Point(0, 1))
>>> t2 = Triangle(Point(0, 0), Point(2, 0), Point(0, 2))
>>> t3 = Triangle(Point(0, 0), Point(3, 0), Point(0, 1))
>>> are_similar(t1, t2)
True
>>> are_similar(t1, t3)
False
Find the centroid (center of mass) of the collection containing only Points, Segments or Polygons. The centroid is the weighted average of the individual centroid where the weights are the lengths (of segments) or areas (of polygons). Overlapping regions will add to the weight of that region.
If there are no objects (or a mixture of objects) then None is returned.
Examples
>>> from sympy import Point, Segment, Polygon
>>> from sympy.geometry.util import centroid
>>> p = Polygon((0, 0), (10, 0), (10, 10))
>>> q = p.translate(0, 20)
>>> p.centroid, q.centroid
(Point(20/3, 10/3), Point(20/3, 70/3))
>>> centroid(p, q)
Point(20/3, 40/3)
>>> p, q = Segment((0, 0), (2, 0)), Segment((0, 0), (2, 2))
>>> centroid(p, q)
Point(1, -sqrt(2) + 2)
>>> centroid(Point(0, 0), Point(2, 0))
Point(1, 0)
Stacking 3 polygons on top of each other effectively triples the weight of that polygon:
>>> p = Polygon((0, 0), (1, 0), (1, 1), (0, 1))
>>> q = Polygon((1, 0), (3, 0), (3, 1), (1, 1))
>>> centroid(p, q)
Point(3/2, 1/2)
>>> centroid(p, p, p, q) # centroid x-coord shifts left
Point(11/10, 1/2)
Stacking the squares vertically above and below p has the same effect:
>>> centroid(p, p.translate(0, 1), p.translate(0, -1), q)
Point(11/10, 1/2)
A point in a 2-dimensional Euclidean space.
Parameters: | coords : sequence of 2 coordinate values. |
---|---|
Raises: | NotImplementedError :
TypeError :
|
See also
Notes
Currently only 2-dimensional points are supported.
Examples
>>> from sympy.geometry import Point
>>> from sympy.abc import x
>>> Point(1, 2)
Point(1, 2)
>>> Point([1, 2])
Point(1, 2)
>>> Point(0, x)
Point(0, x)
Floats are automatically converted to Rational unless the evaluate flag is False:
>>> Point(0.5, 0.25)
Point(1/2, 1/4)
>>> Point(0.5, 0.25, evaluate=False)
Point(0.5, 0.25)
Attributes
x | |
y | |
length |
The Euclidean distance from self to point p.
Parameters: | p : Point |
---|---|
Returns: | distance : number or symbolic expression. |
See also
Examples
>>> from sympy.geometry import Point
>>> p1, p2 = Point(1, 1), Point(4, 5)
>>> p1.distance(p2)
5
>>> from sympy.abc import x, y
>>> p3 = Point(x, y)
>>> p3.distance(Point(0, 0))
sqrt(x**2 + y**2)
Return dot product of self with another Point.
Evaluate the coordinates of the point.
This method will, where possible, create and return a new Point where the coordinates are evaluated as floating point numbers to the precision indicated (default=15).
Returns: | point : Point |
---|
Examples
>>> from sympy import Point, Rational
>>> p1 = Point(Rational(1, 2), Rational(3, 2))
>>> p1
Point(1/2, 3/2)
>>> p1.evalf()
Point(0.5, 1.5)
The intersection between this point and another point.
Parameters: | other : Point |
---|---|
Returns: | intersection : list of Points |
Notes
The return value will either be an empty list if there is no intersection, otherwise it will contain this point.
Examples
>>> from sympy import Point
>>> p1, p2, p3 = Point(0, 0), Point(1, 1), Point(0, 0)
>>> p1.intersection(p2)
[]
>>> p1.intersection(p3)
[Point(0, 0)]
Is a sequence of points collinear?
Test whether or not a set of points are collinear. Returns True if the set of points are collinear, or False otherwise.
Parameters: | points : sequence of Point |
---|---|
Returns: | is_collinear : boolean |
See also
Notes
Slope is preserved everywhere on a line, so the slope between any two points on the line should be the same. Take the first two points, p1 and p2, and create a translated point v1 with p1 as the origin. Now for every other point we create a translated point, vi with p1 also as the origin. Note that these translations preserve slope since everything is consistently translated to a new origin of p1. Since slope is preserved then we have the following equality:
- v1_slope = vi_slope
- v1.y/v1.x = vi.y/vi.x (due to translation)
- v1.y*vi.x = vi.y*v1.x
- v1.y*vi.x - vi.y*v1.x = 0 (*)
Hence, if we have a vi such that the equality in (*) is False then the points are not collinear. We do this test for every point in the list, and if all pass then they are collinear.
Examples
>>> from sympy import Point
>>> from sympy.abc import x
>>> p1, p2 = Point(0, 0), Point(1, 1)
>>> p3, p4, p5 = Point(2, 2), Point(x, x), Point(1, 2)
>>> Point.is_collinear(p1, p2, p3, p4)
True
>>> Point.is_collinear(p1, p2, p3, p5)
False
Is a sequence of points concyclic?
Test whether or not a sequence of points are concyclic (i.e., they lie on a circle).
Parameters: | points : sequence of Points |
---|---|
Returns: | is_concyclic : boolean
|
See also
Notes
No points are not considered to be concyclic. One or two points are definitely concyclic and three points are conyclic iff they are not collinear.
For more than three points, create a circle from the first three points. If the circle cannot be created (i.e., they are collinear) then all of the points cannot be concyclic. If the circle is created successfully then simply check the remaining points for containment in the circle.
Examples
>>> from sympy.geometry import Point
>>> p1, p2 = Point(-1, 0), Point(1, 0)
>>> p3, p4 = Point(0, 1), Point(-1, 2)
>>> Point.is_concyclic(p1, p2, p3)
True
>>> Point.is_concyclic(p1, p2, p3, p4)
False
Treating a Point as a Line, this returns 0 for the length of a Point.
Examples
>>> from sympy import Point
>>> p = Point(0, 1)
>>> p.length
0
The midpoint between self and point p.
Parameters: | p : Point |
---|---|
Returns: | midpoint : Point |
See also
Examples
>>> from sympy.geometry import Point
>>> p1, p2 = Point(1, 1), Point(13, 5)
>>> p1.midpoint(p2)
Point(7, 3)
Evaluate the coordinates of the point.
This method will, where possible, create and return a new Point where the coordinates are evaluated as floating point numbers to the precision indicated (default=15).
Returns: | point : Point |
---|
Examples
>>> from sympy import Point, Rational
>>> p1 = Point(Rational(1, 2), Rational(3, 2))
>>> p1
Point(1/2, 3/2)
>>> p1.evalf()
Point(0.5, 1.5)
Rotate angle radians counterclockwise about Point pt.
Examples
>>> from sympy import Point, pi
>>> t = Point(1, 0)
>>> t.rotate(pi/2)
Point(0, 1)
>>> t.rotate(pi/2, (2, 0))
Point(2, -1)
Scale the coordinates of the Point by multiplying by x and y after subtracting pt – default is (0, 0) – and then adding pt back again (i.e. pt is the point of reference for the scaling).
Examples
>>> from sympy import Point
>>> t = Point(1, 1)
>>> t.scale(2)
Point(2, 1)
>>> t.scale(2, 2)
Point(2, 2)
Return the point after applying the transformation described by the 3x3 Matrix, matrix.
See also
geometry.entity.rotate, geometry.entity.scale, geometry.entity.translate
Shift the Point by adding x and y to the coordinates of the Point.
Examples
>>> from sympy import Point
>>> t = Point(0, 1)
>>> t.translate(2)
Point(2, 1)
>>> t.translate(2, 2)
Point(2, 3)
>>> t + Point(2, 2)
Point(2, 3)
Returns the X coordinate of the Point.
Examples
>>> from sympy import Point
>>> p = Point(0, 1)
>>> p.x
0
Returns the Y coordinate of the Point.
Examples
>>> from sympy import Point
>>> p = Point(0, 1)
>>> p.y
1
An abstract base class for all linear entities (line, ray and segment) in a 2-dimensional Euclidean space.
See also
Notes
This is an abstract class and is not meant to be instantiated. Subclasses should implement the following methods:
- __eq__
- contains
Attributes
p1 | |
p2 | |
coefficients | |
slope | |
points |
The angle formed between the two linear entities.
Parameters: | l1 : LinearEntity l2 : LinearEntity |
---|---|
Returns: | angle : angle in radians |
See also
Notes
From the dot product of vectors v1 and v2 it is known that:
dot(v1, v2) = |v1|*|v2|*cos(A)
where A is the angle formed between the two vectors. We can get the directional vectors of the two lines and readily find the angle between the two using the above formula.
Examples
>>> from sympy import Point, Line
>>> p1, p2, p3 = Point(0, 0), Point(0, 4), Point(2, 0)
>>> l1, l2 = Line(p1, p2), Line(p1, p3)
>>> l1.angle_between(l2)
pi/2
A parameterized point on the Line.
Parameters: | parameter : str, optional
|
---|---|
Returns: | point : Point |
Raises: | ValueError :
|
See also
Examples
>>> from sympy import Point, Line
>>> p1, p2 = Point(1, 0), Point(5, 3)
>>> l1 = Line(p1, p2)
>>> l1.arbitrary_point()
Point(4*t + 1, 3*t)
The coefficients (\(a\), \(b\), \(c\)) for the linear equation \(ax + by + c = 0\).
See also
Examples
>>> from sympy import Point, Line
>>> from sympy.abc import x, y
>>> p1, p2 = Point(0, 0), Point(5, 3)
>>> l = Line(p1, p2)
>>> l.coefficients
(-3, 5, 0)
>>> p3 = Point(x, y)
>>> l2 = Line(p1, p3)
>>> l2.coefficients
(-y, x, 0)
Subclasses should implement this method and should return True if other is on the boundaries of self; False if not on the boundaries of self; None if a determination cannot be made.
The intersection with another geometrical entity.
Parameters: | o : Point or LinearEntity |
---|---|
Returns: | intersection : list of geometrical entities |
See also
Examples
>>> from sympy import Point, Line, Segment
>>> p1, p2, p3 = Point(0, 0), Point(1, 1), Point(7, 7)
>>> l1 = Line(p1, p2)
>>> l1.intersection(p3)
[Point(7, 7)]
>>> p4, p5 = Point(5, 0), Point(0, 3)
>>> l2 = Line(p4, p5)
>>> l1.intersection(l2)
[Point(15/8, 15/8)]
>>> p6, p7 = Point(0, 5), Point(2, 6)
>>> s1 = Segment(p6, p7)
>>> l1.intersection(s1)
[]
Is a sequence of linear entities concurrent?
Two or more linear entities are concurrent if they all intersect at a single point.
Parameters: | lines : a sequence of linear entities. |
---|---|
Returns: | True : if the set of linear entities are concurrent, False : otherwise. |
See also
Notes
Simply take the first two lines and find their intersection. If there is no intersection, then the first two lines were parallel and had no intersection so concurrency is impossible amongst the whole set. Otherwise, check to see if the intersection point of the first two lines is a member on the rest of the lines. If so, the lines are concurrent.
Examples
>>> from sympy import Point, Line
>>> p1, p2 = Point(0, 0), Point(3, 5)
>>> p3, p4 = Point(-2, -2), Point(0, 2)
>>> l1, l2, l3 = Line(p1, p2), Line(p1, p3), Line(p1, p4)
>>> l1.is_concurrent(l2, l3)
True
>>> l4 = Line(p2, p3)
>>> l4.is_concurrent(l2, l3)
False
Are two linear entities parallel?
Parameters: | l1 : LinearEntity l2 : LinearEntity |
---|---|
Returns: | True : if l1 and l2 are parallel, False : otherwise. |
See also
Examples
>>> from sympy import Point, Line
>>> p1, p2 = Point(0, 0), Point(1, 1)
>>> p3, p4 = Point(3, 4), Point(6, 7)
>>> l1, l2 = Line(p1, p2), Line(p3, p4)
>>> Line.is_parallel(l1, l2)
True
>>> p5 = Point(6, 6)
>>> l3 = Line(p3, p5)
>>> Line.is_parallel(l1, l3)
False
Are two linear entities perpendicular?
Parameters: | l1 : LinearEntity l2 : LinearEntity |
---|---|
Returns: | True : if l1 and l2 are perpendicular, False : otherwise. |
See also
Examples
>>> from sympy import Point, Line
>>> p1, p2, p3 = Point(0, 0), Point(1, 1), Point(-1, 1)
>>> l1, l2 = Line(p1, p2), Line(p1, p3)
>>> l1.is_perpendicular(l2)
True
>>> p4 = Point(5, 3)
>>> l3 = Line(p1, p4)
>>> l1.is_perpendicular(l3)
False
Return True if self and other are contained in the same line.
Examples
>>> from sympy import Point, Line
>>> p1, p2, p3 = Point(0, 1), Point(3, 4), Point(2, 3)
>>> l1 = Line(p1, p2)
>>> l2 = Line(p1, p3)
>>> l1.is_similar(l2)
True
The length of the line.
Examples
>>> from sympy import Point, Line
>>> p1, p2 = Point(0, 0), Point(3, 5)
>>> l1 = Line(p1, p2)
>>> l1.length
oo
The first defining point of a linear entity.
See also
Examples
>>> from sympy import Point, Line
>>> p1, p2 = Point(0, 0), Point(5, 3)
>>> l = Line(p1, p2)
>>> l.p1
Point(0, 0)
The second defining point of a linear entity.
See also
Examples
>>> from sympy import Point, Line
>>> p1, p2 = Point(0, 0), Point(5, 3)
>>> l = Line(p1, p2)
>>> l.p2
Point(5, 3)
Create a new Line parallel to this linear entity which passes through the point \(p\).
Parameters: | p : Point |
---|---|
Returns: | line : Line |
See also
Examples
>>> from sympy import Point, Line
>>> p1, p2, p3 = Point(0, 0), Point(2, 3), Point(-2, 2)
>>> l1 = Line(p1, p2)
>>> l2 = l1.parallel_line(p3)
>>> p3 in l2
True
>>> l1.is_parallel(l2)
True
Create a new Line perpendicular to this linear entity which passes through the point \(p\).
Parameters: | p : Point |
---|---|
Returns: | line : Line |
See also
Examples
>>> from sympy import Point, Line
>>> p1, p2, p3 = Point(0, 0), Point(2, 3), Point(-2, 2)
>>> l1 = Line(p1, p2)
>>> l2 = l1.perpendicular_line(p3)
>>> p3 in l2
True
>>> l1.is_perpendicular(l2)
True
Create a perpendicular line segment from \(p\) to this line.
The enpoints of the segment are p and the closest point in the line containing self. (If self is not a line, the point might not be in self.)
Parameters: | p : Point |
---|---|
Returns: | segment : Segment |
See also
Notes
Returns \(p\) itself if \(p\) is on this linear entity.
Examples
>>> from sympy import Point, Line
>>> p1, p2, p3 = Point(0, 0), Point(1, 1), Point(0, 2)
>>> l1 = Line(p1, p2)
>>> s1 = l1.perpendicular_segment(p3)
>>> l1.is_perpendicular(s1)
True
>>> p3 in s1
True
>>> l1.perpendicular_segment(Point(4, 0))
Segment(Point(2, 2), Point(4, 0))
The two points used to define this linear entity.
Returns: | points : tuple of Points |
---|
See also
Examples
>>> from sympy import Point, Line
>>> p1, p2 = Point(0, 0), Point(5, 11)
>>> l1 = Line(p1, p2)
>>> l1.points
(Point(0, 0), Point(5, 11))
Project a point, line, ray, or segment onto this linear entity.
Parameters: | other : Point or LinearEntity (Line, Ray, Segment) |
---|---|
Returns: | projection : Point or LinearEntity (Line, Ray, Segment)
|
Raises: | GeometryError :
|
See also
Notes
A projection involves taking the two points that define the linear entity and projecting those points onto a Line and then reforming the linear entity using these projections. A point P is projected onto a line L by finding the point on L that is closest to P. This is done by creating a perpendicular line through P and L and finding its intersection with L.
Examples
>>> from sympy import Point, Line, Segment, Rational
>>> p1, p2, p3 = Point(0, 0), Point(1, 1), Point(Rational(1, 2), 0)
>>> l1 = Line(p1, p2)
>>> l1.projection(p3)
Point(1/4, 1/4)
>>> p4, p5 = Point(10, 0), Point(12, 1)
>>> s1 = Segment(p4, p5)
>>> l1.projection(s1)
Segment(Point(5, 5), Point(13/2, 13/2))
A random point on a LinearEntity.
Returns: | point : Point |
---|
See also
Examples
>>> from sympy import Point, Line
>>> p1, p2 = Point(0, 0), Point(5, 3)
>>> l1 = Line(p1, p2)
>>> p3 = l1.random_point()
>>> # random point - don't know its coords in advance
>>> p3
Point(...)
>>> # point should belong to the line
>>> p3 in l1
True
The slope of this linear entity, or infinity if vertical.
Returns: | slope : number or sympy expression |
---|
See also
Examples
>>> from sympy import Point, Line
>>> p1, p2 = Point(0, 0), Point(3, 5)
>>> l1 = Line(p1, p2)
>>> l1.slope
5/3
>>> p3 = Point(0, 4)
>>> l2 = Line(p1, p3)
>>> l2.slope
oo
An infinite line in space.
A line is declared with two distinct points or a point and slope as defined using keyword \(slope\).
Parameters: | p1 : Point pt : Point slope : sympy expression |
---|
See also
Notes
At the moment only lines in a 2D space can be declared, because Points can be defined only for 2D spaces.
Examples
>>> import sympy
>>> from sympy import Point
>>> from sympy.abc import L
>>> from sympy.geometry import Line, Segment
>>> L = Line(Point(2,3), Point(3,5))
>>> L
Line(Point(2, 3), Point(3, 5))
>>> L.points
(Point(2, 3), Point(3, 5))
>>> L.equation()
-2*x + y + 1
>>> L.coefficients
(-2, 1, 1)
Instantiate with keyword slope:
>>> Line(Point(0, 0), slope=0)
Line(Point(0, 0), Point(1, 0))
Instantiate with another linear object
>>> s = Segment((0, 0), (0, 1))
>>> Line(s).equation()
x
Return True if o is on this Line, or False otherwise.
The equation of the line: ax + by + c.
Parameters: | x : str, optional
y : str, optional
|
---|---|
Returns: | equation : sympy expression |
See also
Examples
>>> from sympy import Point, Line
>>> p1, p2 = Point(1, 0), Point(5, 3)
>>> l1 = Line(p1, p2)
>>> l1.equation()
-3*x + 4*y + 3
The plot interval for the default geometric plot of line. Gives values that will produce a line that is +/- 5 units long (where a unit is the distance between the two points that define the line).
Parameters: | parameter : str, optional
|
---|---|
Returns: | plot_interval : list (plot interval)
|
Examples
>>> from sympy import Point, Line
>>> p1, p2 = Point(0, 0), Point(5, 3)
>>> l1 = Line(p1, p2)
>>> l1.plot_interval()
[t, -5, 5]
A Ray is a semi-line in the space with a source point and a direction.
Parameters: | p1 : Point
p2 : Point or radian value
|
---|
See also
Notes
At the moment only rays in a 2D space can be declared, because Points can be defined only for 2D spaces.
Examples
>>> import sympy
>>> from sympy import Point, pi
>>> from sympy.abc import r
>>> from sympy.geometry import Ray
>>> r = Ray(Point(2, 3), Point(3, 5))
>>> r = Ray(Point(2, 3), Point(3, 5))
>>> r
Ray(Point(2, 3), Point(3, 5))
>>> r.points
(Point(2, 3), Point(3, 5))
>>> r.source
Point(2, 3)
>>> r.xdirection
oo
>>> r.ydirection
oo
>>> r.slope
2
>>> Ray(Point(0, 0), angle=pi/4).slope
1
Attributes
source | |
xdirection | |
ydirection |
Is other GeometryEntity contained in this Ray?
The plot interval for the default geometric plot of the Ray. Gives values that will produce a ray that is 10 units long (where a unit is the distance between the two points that define the ray).
Parameters: | parameter : str, optional
|
---|---|
Returns: | plot_interval : list
|
Examples
>>> from sympy import Point, Ray, pi
>>> r = Ray((0, 0), angle=pi/4)
>>> r.plot_interval()
[t, 0, 10]
The point from which the ray emanates.
See also
Examples
>>> from sympy import Point, Ray
>>> p1, p2 = Point(0, 0), Point(4, 1)
>>> r1 = Ray(p1, p2)
>>> r1.source
Point(0, 0)
The x direction of the ray.
Positive infinity if the ray points in the positive x direction, negative infinity if the ray points in the negative x direction, or 0 if the ray is vertical.
See also
Examples
>>> from sympy import Point, Ray
>>> p1, p2, p3 = Point(0, 0), Point(1, 1), Point(0, -1)
>>> r1, r2 = Ray(p1, p2), Ray(p1, p3)
>>> r1.xdirection
oo
>>> r2.xdirection
0
The y direction of the ray.
Positive infinity if the ray points in the positive y direction, negative infinity if the ray points in the negative y direction, or 0 if the ray is horizontal.
See also
Examples
>>> from sympy import Point, Ray
>>> p1, p2, p3 = Point(0, 0), Point(-1, -1), Point(-1, 0)
>>> r1, r2 = Ray(p1, p2), Ray(p1, p3)
>>> r1.ydirection
-oo
>>> r2.ydirection
0
An undirected line segment in space.
Parameters: | p1 : Point p2 : Point |
---|
See also
Notes
At the moment only segments in a 2D space can be declared, because Points can be defined only for 2D spaces.
Examples
>>> import sympy
>>> from sympy import Point
>>> from sympy.abc import s
>>> from sympy.geometry import Segment
>>> Segment((1, 0), (1, 1)) # tuples are interpreted as pts
Segment(Point(1, 0), Point(1, 1))
>>> s = Segment(Point(4, 3), Point(1, 1))
>>> s
Segment(Point(1, 1), Point(4, 3))
>>> s.points
(Point(1, 1), Point(4, 3))
>>> s.slope
2/3
>>> s.length
sqrt(13)
>>> s.midpoint
Point(5/2, 2)
Attributes
length | number or sympy expression | |
midpoint | Point |
Is the other GeometryEntity contained within this Segment?
Examples
>>> from sympy import Point, Segment
>>> p1, p2 = Point(0, 1), Point(3, 4)
>>> s = Segment(p1, p2)
>>> s2 = Segment(p2, p1)
>>> s.contains(s2)
True
Finds the shortest distance between a line segment and a point.
Raises: | NotImplementedError is raised if o is not a Point : |
---|
Examples
>>> from sympy import Point, Segment
>>> p1, p2 = Point(0, 1), Point(3, 4)
>>> s = Segment(p1, p2)
>>> s.distance(Point(10, 15))
sqrt(170)
The length of the line segment.
See also
Examples
>>> from sympy import Point, Segment
>>> p1, p2 = Point(0, 0), Point(4, 3)
>>> s1 = Segment(p1, p2)
>>> s1.length
5
The midpoint of the line segment.
See also
Examples
>>> from sympy import Point, Segment
>>> p1, p2 = Point(0, 0), Point(4, 3)
>>> s1 = Segment(p1, p2)
>>> s1.midpoint
Point(2, 3/2)
The perpendicular bisector of this segment.
If no point is specified or the point specified is not on the bisector then the bisector is returned as a Line. Otherwise a Segment is returned that joins the point specified and the intersection of the bisector and the segment.
Parameters: | p : Point |
---|---|
Returns: | bisector : Line or Segment |
See also
Examples
>>> from sympy import Point, Segment
>>> p1, p2, p3 = Point(0, 0), Point(6, 6), Point(5, 1)
>>> s1 = Segment(p1, p2)
>>> s1.perpendicular_bisector()
Line(Point(3, 3), Point(9, -3))
>>> s1.perpendicular_bisector(p3)
Segment(Point(3, 3), Point(5, 1))
The plot interval for the default geometric plot of the Segment. Gives values that will produce the full segment in a plot.
Parameters: | parameter : str, optional
|
---|---|
Returns: | plot_interval : list
|
Examples
>>> from sympy import Point, Segment
>>> p1, p2 = Point(0, 0), Point(5, 3)
>>> s1 = Segment(p1, p2)
>>> s1.plot_interval()
[t, 0, 1]
A curve in space.
A curve is defined by parametric functions for the coordinates, a parameter and the lower and upper bounds for the parameter value.
Parameters: | function : list of functions limits : 3-tuple
|
---|---|
Raises: | ValueError :
|
Examples
>>> from sympy import sin, cos, Symbol, interpolate
>>> from sympy.abc import t, a
>>> from sympy.geometry import Curve
>>> C = Curve((sin(t), cos(t)), (t, 0, 2))
>>> C.functions
(sin(t), cos(t))
>>> C.limits
(t, 0, 2)
>>> C.parameter
t
>>> C = Curve((t, interpolate([1, 4, 9, 16], t)), (t, 0, 1)); C
Curve((t, t**2), (t, 0, 1))
>>> C.subs(t, 4)
Point(4, 16)
>>> C.arbitrary_point(a)
Point(a, a**2)
Attributes
functions | |
parameter | |
limits |
A parameterized point on the curve.
Parameters: | parameter : str or Symbol, optional
|
---|---|
Returns: | arbitrary_point : Point |
Raises: | ValueError :
|
See also
Examples
>>> from sympy import Symbol
>>> from sympy.abc import s
>>> from sympy.geometry import Curve
>>> C = Curve([2*s, s**2], (s, 0, 2))
>>> C.arbitrary_point()
Point(2*t, t**2)
>>> C.arbitrary_point(C.parameter)
Point(2*s, s**2)
>>> C.arbitrary_point(None)
Point(2*s, s**2)
>>> C.arbitrary_point(Symbol('a'))
Point(2*a, a**2)
Return a set of symbols other than the bound symbols used to parametrically define the Curve.
Examples
>>> from sympy.abc import t, a
>>> from sympy.geometry import Curve
>>> Curve((t, t**2), (t, 0, 2)).free_symbols
set()
>>> Curve((t, t**2), (t, a, 2)).free_symbols
set([a])
The functions specifying the curve.
Returns: | functions : list of parameterized coordinate functions. |
---|
See also
Examples
>>> from sympy.abc import t
>>> from sympy.geometry import Curve
>>> C = Curve((t, t**2), (t, 0, 2))
>>> C.functions
(t, t**2)
The limits for the curve.
Returns: | limits : tuple
|
---|
See also
Examples
>>> from sympy.abc import t
>>> from sympy.geometry import Curve
>>> C = Curve([t, t**3], (t, -2, 2))
>>> C.limits
(t, -2, 2)
The curve function variable.
Returns: | parameter : SymPy symbol |
---|
See also
Examples
>>> from sympy.abc import t
>>> from sympy.geometry import Curve
>>> C = Curve([t, t**2], (t, 0, 2))
>>> C.parameter
t
The plot interval for the default geometric plot of the curve.
Parameters: | parameter : str or Symbol, optional
|
---|---|
Returns: | plot_interval : list (plot interval)
|
See also
Examples
>>> from sympy import Curve, sin
>>> from sympy.abc import x, t, s
>>> Curve((x, sin(x)), (x, 1, 2)).plot_interval()
[t, 1, 2]
>>> Curve((x, sin(x)), (x, 1, 2)).plot_interval(s)
[s, 1, 2]
Rotate angle radians counterclockwise about Point pt.
The default pt is the origin, Point(0, 0).
Examples
>>> from sympy.geometry.curve import Curve
>>> from sympy.abc import x
>>> from sympy import pi
>>> Curve((x, x), (x, 0, 1)).rotate(pi/2)
Curve((-x, x), (x, 0, 1))
Override GeometryEntity.scale since Curve is not made up of Points.
Examples
>>> from sympy.geometry.curve import Curve
>>> from sympy import pi
>>> from sympy.abc import x
>>> Curve((x, x), (x, 0, 1)).scale(2)
Curve((2*x, x), (x, 0, 1))
Translate the Curve by (x, y).
Examples
>>> from sympy.geometry.curve import Curve
>>> from sympy import pi
>>> from sympy.abc import x
>>> Curve((x, x), (x, 0, 1)).translate(1, 2)
Curve((x + 1, x + 2), (x, 0, 1))
An elliptical GeometryEntity.
Parameters: | center : Point, optional
hradius : number or SymPy expression, optional vradius : number or SymPy expression, optional eccentricity : number or SymPy expression, optional
|
---|---|
Raises: | GeometryError :
TypeError :
|
See also
Notes
Constructed from a center and two radii, the first being the horizontal radius (along the x-axis) and the second being the vertical radius (along the y-axis).
When symbolic value for hradius and vradius are used, any calculation that refers to the foci or the major or minor axis will assume that the ellipse has its major radius on the x-axis. If this is not true then a manual rotation is necessary.
Examples
>>> from sympy import Ellipse, Point, Rational
>>> e1 = Ellipse(Point(0, 0), 5, 1)
>>> e1.hradius, e1.vradius
(5, 1)
>>> e2 = Ellipse(Point(3, 1), hradius=3, eccentricity=Rational(4, 5))
>>> e2
Ellipse(Point(3, 1), 3, 9/5)
Plotting:
>>> from sympy.plotting.pygletplot import PygletPlot as Plot
>>> from sympy import Circle, Segment
>>> c1 = Circle(Point(0,0), 1)
>>> Plot(c1)
[0]: cos(t), sin(t), 'mode=parametric'
>>> p = Plot()
>>> p[0] = c1
>>> radius = Segment(c1.center, c1.random_point())
>>> p[1] = radius
>>> p
[0]: cos(t), sin(t), 'mode=parametric'
[1]: t*cos(1.546086215036205357975518382),
t*sin(1.546086215036205357975518382), 'mode=parametric'
Attributes
center | |
hradius | |
vradius | |
area | |
circumference | |
eccentricity | |
periapsis | |
apoapsis | |
focus_distance | |
foci |
The apoapsis of the ellipse.
The greatest distance between the focus and the contour.
Returns: | apoapsis : number |
---|
See also
Examples
>>> from sympy import Point, Ellipse
>>> p1 = Point(0, 0)
>>> e1 = Ellipse(p1, 3, 1)
>>> e1.apoapsis
2*sqrt(2) + 3
A parameterized point on the ellipse.
Parameters: | parameter : str, optional
|
---|---|
Returns: | arbitrary_point : Point |
Raises: | ValueError :
|
See also
Examples
>>> from sympy import Point, Ellipse
>>> e1 = Ellipse(Point(0, 0), 3, 2)
>>> e1.arbitrary_point()
Point(3*cos(t), 2*sin(t))
The area of the ellipse.
Returns: | area : number |
---|
Examples
>>> from sympy import Point, Ellipse
>>> p1 = Point(0, 0)
>>> e1 = Ellipse(p1, 3, 1)
>>> e1.area
3*pi
The center of the ellipse.
Returns: | center : number |
---|
See also
Examples
>>> from sympy import Point, Ellipse
>>> p1 = Point(0, 0)
>>> e1 = Ellipse(p1, 3, 1)
>>> e1.center
Point(0, 0)
The circumference of the ellipse.
Examples
>>> from sympy import Point, Ellipse
>>> p1 = Point(0, 0)
>>> e1 = Ellipse(p1, 3, 1)
>>> e1.circumference
12*Integral(sqrt((-8*_x**2/9 + 1)/(-_x**2 + 1)), (_x, 0, 1))
The eccentricity of the ellipse.
Returns: | eccentricity : number |
---|
Examples
>>> from sympy import Point, Ellipse, sqrt
>>> p1 = Point(0, 0)
>>> e1 = Ellipse(p1, 3, sqrt(2))
>>> e1.eccentricity
sqrt(7)/3
Return True if p is enclosed by (is inside of) self.
Parameters: | p : Point |
---|---|
Returns: | encloses_point : True, False or None |
See also
Notes
Being on the border of self is considered False.
Examples
>>> from sympy import Ellipse, S
>>> from sympy.abc import t
>>> e = Ellipse((0, 0), 3, 2)
>>> e.encloses_point((0, 0))
True
>>> e.encloses_point(e.arbitrary_point(t).subs(t, S.Half))
False
>>> e.encloses_point((4, 0))
False
The equation of the ellipse.
Parameters: | x : str, optional
y : str, optional
|
---|---|
Returns: | equation : sympy expression |
See also
Examples
>>> from sympy import Point, Ellipse
>>> e1 = Ellipse(Point(1, 0), 3, 2)
>>> e1.equation()
y**2/4 + (x/3 - 1/3)**2 - 1
The foci of the ellipse.
Raises: | ValueError :
|
---|
Notes
The foci can only be calculated if the major/minor axes are known.
Examples
>>> from sympy import Point, Ellipse
>>> p1 = Point(0, 0)
>>> e1 = Ellipse(p1, 3, 1)
>>> e1.foci
(Point(-2*sqrt(2), 0), Point(2*sqrt(2), 0))
The focale distance of the ellipse.
The distance between the center and one focus.
Returns: | focus_distance : number |
---|
See also
Examples
>>> from sympy import Point, Ellipse
>>> p1 = Point(0, 0)
>>> e1 = Ellipse(p1, 3, 1)
>>> e1.focus_distance
2*sqrt(2)
The horizontal radius of the ellipse.
Returns: | hradius : number |
---|
Examples
>>> from sympy import Point, Ellipse
>>> p1 = Point(0, 0)
>>> e1 = Ellipse(p1, 3, 1)
>>> e1.hradius
3
The intersection of this ellipse and another geometrical entity \(o\).
Parameters: | o : GeometryEntity |
---|---|
Returns: | intersection : list of GeometryEntity objects |
See also
Notes
Currently supports intersections with Point, Line, Segment, Ray, Circle and Ellipse types.
Examples
>>> from sympy import Ellipse, Point, Line, sqrt
>>> e = Ellipse(Point(0, 0), 5, 7)
>>> e.intersection(Point(0, 0))
[]
>>> e.intersection(Point(5, 0))
[Point(5, 0)]
>>> e.intersection(Line(Point(0,0), Point(0, 1)))
[Point(0, -7), Point(0, 7)]
>>> e.intersection(Line(Point(5,0), Point(5, 1)))
[Point(5, 0)]
>>> e.intersection(Line(Point(6,0), Point(6, 1)))
[]
>>> e = Ellipse(Point(-1, 0), 4, 3)
>>> e.intersection(Ellipse(Point(1, 0), 4, 3))
[Point(0, -3*sqrt(15)/4), Point(0, 3*sqrt(15)/4)]
>>> e.intersection(Ellipse(Point(5, 0), 4, 3))
[Point(2, -3*sqrt(7)/4), Point(2, 3*sqrt(7)/4)]
>>> e.intersection(Ellipse(Point(100500, 0), 4, 3))
[]
>>> e.intersection(Ellipse(Point(0, 0), 3, 4))
[Point(-363/175, -48*sqrt(111)/175), Point(-363/175, 48*sqrt(111)/175),
Point(3, 0)]
>>> e.intersection(Ellipse(Point(-1, 0), 3, 4))
[Point(-17/5, -12/5), Point(-17/5, 12/5), Point(7/5, -12/5),
Point(7/5, 12/5)]
Is \(o\) tangent to the ellipse?
Parameters: | o : GeometryEntity
|
---|---|
Returns: | is_tangent: boolean :
|
Raises: | NotImplementedError :
|
See also
Examples
>>> from sympy import Point, Ellipse, Line
>>> p0, p1, p2 = Point(0, 0), Point(3, 0), Point(3, 3)
>>> e1 = Ellipse(p0, 3, 2)
>>> l1 = Line(p1, p2)
>>> e1.is_tangent(l1)
True
Longer axis of the ellipse (if it can be determined) else hradius.
Returns: | major : number or expression |
---|
Examples
>>> from sympy import Point, Ellipse, Symbol
>>> p1 = Point(0, 0)
>>> e1 = Ellipse(p1, 3, 1)
>>> e1.major
3
>>> a = Symbol('a')
>>> b = Symbol('b')
>>> Ellipse(p1, a, b).major
a
>>> Ellipse(p1, b, a).major
b
>>> m = Symbol('m')
>>> M = m + 1
>>> Ellipse(p1, m, M).major
m + 1
Shorter axis of the ellipse (if it can be determined) else vradius.
Returns: | minor : number or expression |
---|
Examples
>>> from sympy import Point, Ellipse, Symbol
>>> p1 = Point(0, 0)
>>> e1 = Ellipse(p1, 3, 1)
>>> e1.minor
1
>>> a = Symbol('a')
>>> b = Symbol('b')
>>> Ellipse(p1, a, b).minor
b
>>> Ellipse(p1, b, a).minor
a
>>> m = Symbol('m')
>>> M = m + 1
>>> Ellipse(p1, m, M).minor
m
The periapsis of the ellipse.
The shortest distance between the focus and the contour.
Returns: | periapsis : number |
---|
See also
Examples
>>> from sympy import Point, Ellipse
>>> p1 = Point(0, 0)
>>> e1 = Ellipse(p1, 3, 1)
>>> e1.periapsis
-2*sqrt(2) + 3
The plot interval for the default geometric plot of the Ellipse.
Parameters: | parameter : str, optional
|
---|---|
Returns: | plot_interval : list
|
Examples
>>> from sympy import Point, Ellipse
>>> e1 = Ellipse(Point(0, 0), 3, 2)
>>> e1.plot_interval()
[t, -pi, pi]
A random point on the ellipse.
Returns: | point : Point |
---|
Notes
An arbitrary_point with a random value of t substituted into it may not test as being on the ellipse because the expression tested that a point is on the ellipse doesn’t simplify to zero and doesn’t evaluate exactly to zero:
>>> from sympy.abc import t
>>> e1.arbitrary_point(t)
Point(3*cos(t), 2*sin(t))
>>> p2 = _.subs(t, 0.1)
>>> p2 in e1
False
Note that arbitrary_point routine does not take this approach. A value for cos(t) and sin(t) (not t) is substituted into the arbitrary point. There is a small chance that this will give a point that will not test as being in the ellipse, so the process is repeated (up to 10 times) until a valid point is obtained.
Examples
>>> from sympy import Point, Ellipse, Segment
>>> e1 = Ellipse(Point(0, 0), 3, 2)
>>> e1.random_point() # gives some random point
Point(...)
>>> p1 = e1.random_point(seed=0); p1.n(2)
Point(2.1, 1.4)
The random_point method assures that the point will test as being in the ellipse:
>>> p1 in e1
True
Override GeometryEntity.reflect since the radius is not a GeometryEntity.
Examples
>>> from sympy import Circle, Line
>>> Circle((0, 1), 1).reflect(Line((0, 0), (1, 1)))
Circle(Point(1, 0), -1)
Rotate angle radians counterclockwise about Point pt.
Note: since the general ellipse is not supported, the axes of the ellipse will not be rotated. Only the center is rotated to a new position.
Examples
>>> from sympy import Ellipse, pi
>>> Ellipse((1, 0), 2, 1).rotate(pi/2)
Ellipse(Point(0, 1), 2, 1)
Override GeometryEntity.scale since it is the major and minor axes which must be scaled and they are not GeometryEntities.
Examples
>>> from sympy import Ellipse
>>> Ellipse((0, 0), 2, 1).scale(2, 4)
Circle(Point(0, 0), 4)
>>> Ellipse((0, 0), 2, 1).scale(2)
Ellipse(Point(0, 0), 4, 1)
Tangent lines between \(p\) and the ellipse.
If \(p\) is on the ellipse, returns the tangent line through point \(p\). Otherwise, returns the tangent line(s) from \(p\) to the ellipse, or None if no tangent line is possible (e.g., \(p\) inside ellipse).
Parameters: | p : Point |
---|---|
Returns: | tangent_lines : list with 1 or 2 Lines |
Raises: | NotImplementedError :
|
Examples
>>> from sympy import Point, Ellipse
>>> e1 = Ellipse(Point(0, 0), 3, 2)
>>> e1.tangent_lines(Point(3, 0))
[Line(Point(3, 0), Point(3, -12))]
>>> # This will plot an ellipse together with a tangent line.
>>> from sympy.plotting.pygletplot import PygletPlot as Plot
>>> from sympy import Point, Ellipse
>>> e = Ellipse(Point(0,0), 3, 2)
>>> t = e.tangent_lines(e.random_point())
>>> p = Plot()
>>> p[0] = e
>>> p[1] = t
The vertical radius of the ellipse.
Returns: | vradius : number |
---|
Examples
>>> from sympy import Point, Ellipse
>>> p1 = Point(0, 0)
>>> e1 = Ellipse(p1, 3, 1)
>>> e1.vradius
1
A circle in space.
Constructed simply from a center and a radius, or from three non-collinear points.
Parameters: | center : Point radius : number or sympy expression points : sequence of three Points |
---|---|
Raises: | GeometryError :
|
See also
Examples
>>> from sympy.geometry import Point, Circle
>>> # a circle constructed from a center and radius
>>> c1 = Circle(Point(0, 0), 5)
>>> c1.hradius, c1.vradius, c1.radius
(5, 5, 5)
>>> # a circle costructed from three points
>>> c2 = Circle(Point(0, 0), Point(1, 1), Point(1, 0))
>>> c2.hradius, c2.vradius, c2.radius, c2.center
(sqrt(2)/2, sqrt(2)/2, sqrt(2)/2, Point(1/2, 1/2))
Attributes
radius (synonymous with hradius, vradius, major and minor) | |
circumference | |
equation |
The circumference of the circle.
Returns: | circumference : number or SymPy expression |
---|
Examples
>>> from sympy import Point, Circle
>>> c1 = Circle(Point(3, 4), 6)
>>> c1.circumference
12*pi
The equation of the circle.
Parameters: | x : str or Symbol, optional
y : str or Symbol, optional
|
---|---|
Returns: | equation : SymPy expression |
Examples
>>> from sympy import Point, Circle
>>> c1 = Circle(Point(0, 0), 5)
>>> c1.equation()
x**2 + y**2 - 25
The intersection of this circle with another geometrical entity.
Parameters: | o : GeometryEntity |
---|---|
Returns: | intersection : list of GeometryEntities |
Examples
>>> from sympy import Point, Circle, Line, Ray
>>> p1, p2, p3 = Point(0, 0), Point(5, 5), Point(6, 0)
>>> p4 = Point(5, 0)
>>> c1 = Circle(p1, 5)
>>> c1.intersection(p2)
[]
>>> c1.intersection(p4)
[Point(5, 0)]
>>> c1.intersection(Ray(p1, p2))
[Point(5*sqrt(2)/2, 5*sqrt(2)/2)]
>>> c1.intersection(Line(p2, p3))
[]
The radius of the circle.
Returns: | radius : number or sympy expression |
---|
See also
Ellipse.major, Ellipse.minor, Ellipse.hradius, Ellipse.vradius
Examples
>>> from sympy import Point, Circle
>>> c1 = Circle(Point(3, 4), 6)
>>> c1.radius
6
Override GeometryEntity.reflect since the radius is not a GeometryEntity.
Examples
>>> from sympy import Circle, Line
>>> Circle((0, 1), 1).reflect(Line((0, 0), (1, 1)))
Circle(Point(1, 0), -1)
Override GeometryEntity.scale since the radius is not a GeometryEntity.
Examples
>>> from sympy import Circle
>>> Circle((0, 0), 1).scale(2, 2)
Circle(Point(0, 0), 2)
>>> Circle((0, 0), 1).scale(2, 4)
Ellipse(Point(0, 0), 2, 4)
This Ellipse property is an alias for the Circle’s radius.
Whereas hradius, major and minor can use Ellipse’s conventions, the vradius does not exist for a circle. It is always a positive value in order that the Circle, like Polygons, will have an area that can be positive or negative as determined by the sign of the hradius.
Examples
>>> from sympy import Point, Circle
>>> c1 = Circle(Point(3, 4), 6)
>>> c1.vradius
6
A two-dimensional polygon.
A simple polygon in space. Can be constructed from a sequence of points or from a center, radius, number of sides and rotation angle.
Parameters: | vertices : sequence of Points |
---|---|
Raises: | GeometryError :
|
Notes
Polygons are treated as closed paths rather than 2D areas so some calculations can be be negative or positive (e.g., area) based on the orientation of the points.
Any consecutive identical points are reduced to a single point and any points collinear and between two points will be removed unless they are needed to define an explicit intersection (see examples).
A Triangle, Segment or Point will be returned when there are 3 or fewer points provided.
Examples
>>> from sympy import Point, Polygon, pi
>>> p1, p2, p3, p4, p5 = [(0, 0), (1, 0), (5, 1), (0, 1), (3, 0)]
>>> Polygon(p1, p2, p3, p4)
Polygon(Point(0, 0), Point(1, 0), Point(5, 1), Point(0, 1))
>>> Polygon(p1, p2)
Segment(Point(0, 0), Point(1, 0))
>>> Polygon(p1, p2, p5)
Segment(Point(0, 0), Point(3, 0))
While the sides of a polygon are not allowed to cross implicitly, they can do so explicitly. For example, a polygon shaped like a Z with the top left connecting to the bottom right of the Z must have the point in the middle of the Z explicitly given:
>>> mid = Point(1, 1)
>>> Polygon((0, 2), (2, 2), mid, (0, 0), (2, 0), mid).area
0
>>> Polygon((0, 2), (2, 2), mid, (2, 0), (0, 0), mid).area
-2
When the the keyword \(n\) is used to define the number of sides of the Polygon then a RegularPolygon is created and the other arguments are interpreted as center, radius and rotation. The unrotated RegularPolygon will always have a vertex at Point(r, 0) where \(r\) is the radius of the circle that circumscribes the RegularPolygon. Its method \(spin\) can be used to increment that angle.
>>> p = Polygon((0,0), 1, n=3)
>>> p
RegularPolygon(Point(0, 0), 1, 3, 0)
>>> p.vertices[0]
Point(1, 0)
>>> p.args[0]
Point(0, 0)
>>> p.spin(pi/2)
>>> p.vertices[0]
Point(0, 1)
Attributes
area | |
angles | |
perimeter | |
vertices | |
centroid | |
sides |
The internal angle at each vertex.
Returns: | angles : dict
|
---|
Examples
>>> from sympy import Point, Polygon
>>> p1, p2, p3, p4 = map(Point, [(0, 0), (1, 0), (5, 1), (0, 1)])
>>> poly = Polygon(p1, p2, p3, p4)
>>> poly.angles[p1]
pi/2
>>> poly.angles[p2]
acos(-4*sqrt(17)/17)
A parameterized point on the polygon.
The parameter, varying from 0 to 1, assigns points to the position on the perimeter that is that fraction of the total perimeter. So the point evaluated at t=1/2 would return the point from the first vertex that is 1/2 way around the polygon.
Parameters: | parameter : str, optional
|
---|---|
Returns: | arbitrary_point : Point |
Raises: | ValueError :
|
See also
Examples
>>> from sympy import Polygon, S, Symbol
>>> t = Symbol('t', real=True)
>>> tri = Polygon((0, 0), (1, 0), (1, 1))
>>> p = tri.arbitrary_point('t')
>>> perimeter = tri.perimeter
>>> s1, s2 = [s.length for s in tri.sides[:2]]
>>> p.subs(t, (s1 + s2/2)/perimeter)
Point(1, 1/2)
The area of the polygon.
See also
Notes
The area calculation can be positive or negative based on the orientation of the points.
Examples
>>> from sympy import Point, Polygon
>>> p1, p2, p3, p4 = map(Point, [(0, 0), (1, 0), (5, 1), (0, 1)])
>>> poly = Polygon(p1, p2, p3, p4)
>>> poly.area
3
The centroid of the polygon.
Returns: | centroid : Point |
---|
Examples
>>> from sympy import Point, Polygon
>>> p1, p2, p3, p4 = map(Point, [(0, 0), (1, 0), (5, 1), (0, 1)])
>>> poly = Polygon(p1, p2, p3, p4)
>>> poly.centroid
Point(31/18, 11/18)
Returns the shortest distance between self and o.
If o is a point, then self does not need to be convex. If o is another polygon self and o must be complex.
Examples
>>> from sympy import Point, Polygon, RegularPolygon
>>> p1, p2 = map(Point, [(0, 0), (7, 5)])
>>> poly = Polygon(*RegularPolygon(p1, 1, 3).vertices)
>>> poly.distance(p2)
sqrt(61)
Return True if p is enclosed by (is inside of) self.
Parameters: | p : Point |
---|---|
Returns: | encloses_point : True, False or None |
Notes
Being on the border of self is considered False.
References
[1] http://www.ariel.com.au/a/python-point-int-poly.html
Examples
>>> from sympy import Polygon, Point
>>> from sympy.abc import t
>>> p = Polygon((0, 0), (4, 0), (4, 4))
>>> p.encloses_point(Point(2, 1))
True
>>> p.encloses_point(Point(2, 2))
False
>>> p.encloses_point(Point(5, 5))
False
The intersection of two polygons.
The intersection may be empty and can contain individual Points and complete Line Segments.
Parameters: | other: Polygon : |
---|---|
Returns: | intersection : list
|
Examples
>>> from sympy import Point, Polygon
>>> p1, p2, p3, p4 = map(Point, [(0, 0), (1, 0), (5, 1), (0, 1)])
>>> poly1 = Polygon(p1, p2, p3, p4)
>>> p5, p6, p7 = map(Point, [(3, 2), (1, -1), (0, 2)])
>>> poly2 = Polygon(p5, p6, p7)
>>> poly1.intersection(poly2)
[Point(2/3, 0), Point(9/5, 1/5), Point(7/3, 1), Point(1/3, 1)]
Is the polygon convex?
A polygon is convex if all its interior angles are less than 180 degrees.
Returns: | is_convex : boolean
|
---|
See also
Examples
>>> from sympy import Point, Polygon
>>> p1, p2, p3, p4 = map(Point, [(0, 0), (1, 0), (5, 1), (0, 1)])
>>> poly = Polygon(p1, p2, p3, p4)
>>> poly.is_convex()
True
The perimeter of the polygon.
Returns: | perimeter : number or Basic instance |
---|
See also
Examples
>>> from sympy import Point, Polygon
>>> p1, p2, p3, p4 = map(Point, [(0, 0), (1, 0), (5, 1), (0, 1)])
>>> poly = Polygon(p1, p2, p3, p4)
>>> poly.perimeter
sqrt(17) + 7
The plot interval for the default geometric plot of the polygon.
Parameters: | parameter : str, optional
|
---|---|
Returns: | plot_interval : list (plot interval)
|
Examples
>>> from sympy import Polygon
>>> p = Polygon((0, 0), (1, 0), (1, 1))
>>> p.plot_interval()
[t, 0, 1]
The line segments that form the sides of the polygon.
Returns: | sides : list of sides
|
---|
Notes
The Segments that represent the sides are an undirected line segment so cannot be used to tell the orientation of the polygon.
Examples
>>> from sympy import Point, Polygon
>>> p1, p2, p3, p4 = map(Point, [(0, 0), (1, 0), (5, 1), (0, 1)])
>>> poly = Polygon(p1, p2, p3, p4)
>>> poly.sides
[Segment(Point(0, 0), Point(1, 0)),
Segment(Point(1, 0), Point(5, 1)),
Segment(Point(0, 1), Point(5, 1)), Segment(Point(0, 0), Point(0, 1))]
The vertices of the polygon.
Returns: | vertices : tuple of Points |
---|
See also
Notes
When iterating over the vertices, it is more efficient to index self rather than to request the vertices and index them. Only use the vertices when you want to process all of them at once. This is even more important with RegularPolygons that calculate each vertex.
Examples
>>> from sympy import Point, Polygon
>>> p1, p2, p3, p4 = map(Point, [(0, 0), (1, 0), (5, 1), (0, 1)])
>>> poly = Polygon(p1, p2, p3, p4)
>>> poly.vertices
(Point(0, 0), Point(1, 0), Point(5, 1), Point(0, 1))
>>> poly.args[0]
Point(0, 0)
A regular polygon.
Such a polygon has all internal angles equal and all sides the same length.
Parameters: | center : Point radius : number or Basic instance
n : int
|
---|---|
Raises: | GeometryError :
|
See also
Notes
A RegularPolygon can be instantiated with Polygon with the kwarg n.
Regular polygons are instantiated with a center, radius, number of sides and a rotation angle. Whereas the arguments of a Polygon are vertices, the vertices of the RegularPolygon must be obtained with the vertices method.
Examples
>>> from sympy.geometry import RegularPolygon, Point
>>> r = RegularPolygon(Point(0, 0), 5, 3)
>>> r
RegularPolygon(Point(0, 0), 5, 3, 0)
>>> r.vertices[0]
Point(5, 0)
Attributes
vertices | |
center | |
radius | |
rotation | |
apothem | |
interior_angle | |
exterior_angle | |
circumcircle | |
incircle | |
angles |
Returns a dictionary with keys, the vertices of the Polygon, and values, the interior angle at each vertex.
Examples
>>> from sympy import RegularPolygon, Point
>>> r = RegularPolygon(Point(0, 0), 5, 3)
>>> r.angles
{Point(-5/2, -5*sqrt(3)/2): pi/3,
Point(-5/2, 5*sqrt(3)/2): pi/3,
Point(5, 0): pi/3}
The inradius of the RegularPolygon.
The apothem/inradius is the radius of the inscribed circle.
Returns: | apothem : number or instance of Basic |
---|
Examples
>>> from sympy import Symbol
>>> from sympy.geometry import RegularPolygon, Point
>>> radius = Symbol('r')
>>> rp = RegularPolygon(Point(0, 0), radius, 4)
>>> rp.apothem
sqrt(2)*r/2
Returns the area.
Examples
>>> from sympy.geometry import RegularPolygon
>>> square = RegularPolygon((0, 0), 1, 4)
>>> square.area
2
>>> _ == square.length**2
True
Returns the center point, the radius, the number of sides, and the orientation angle.
Examples
>>> from sympy import RegularPolygon, Point
>>> r = RegularPolygon(Point(0, 0), 5, 3)
>>> r.args
(Point(0, 0), 5, 3, 0)
The center of the RegularPolygon
This is also the center of the circumscribing circle.
Returns: | center : Point |
---|
Examples
>>> from sympy.geometry import RegularPolygon, Point
>>> rp = RegularPolygon(Point(0, 0), 5, 4)
>>> rp.center
Point(0, 0)
The center of the RegularPolygon
This is also the center of the circumscribing circle.
Returns: | center : Point |
---|
Examples
>>> from sympy.geometry import RegularPolygon, Point
>>> rp = RegularPolygon(Point(0, 0), 5, 4)
>>> rp.center
Point(0, 0)
Alias for center.
Examples
>>> from sympy.geometry import RegularPolygon, Point
>>> rp = RegularPolygon(Point(0, 0), 5, 4)
>>> rp.circumcenter
Point(0, 0)
The circumcircle of the RegularPolygon.
Returns: | circumcircle : Circle |
---|
See also
Examples
>>> from sympy.geometry import RegularPolygon, Point
>>> rp = RegularPolygon(Point(0, 0), 4, 8)
>>> rp.circumcircle
Circle(Point(0, 0), 4)
Alias for radius.
Examples
>>> from sympy import Symbol
>>> from sympy.geometry import RegularPolygon, Point
>>> radius = Symbol('r')
>>> rp = RegularPolygon(Point(0, 0), radius, 4)
>>> rp.circumradius
r
Return True if p is enclosed by (is inside of) self.
Parameters: | p : Point |
---|---|
Returns: | encloses_point : True, False or None |
Notes
Being on the border of self is considered False.
The general Polygon.encloses_point method is called only if a point is not within or beyond the incircle or circumcircle, respectively.
Examples
>>> from sympy import RegularPolygon, S, Point, Symbol
>>> p = RegularPolygon((0, 0), 3, 4)
>>> p.encloses_point(Point(0, 0))
True
>>> r, R = p.inradius, p.circumradius
>>> p.encloses_point(Point((r + R)/2, 0))
True
>>> p.encloses_point(Point(R/2, R/2 + (R - r)/10))
False
>>> t = Symbol('t', real=True)
>>> p.encloses_point(p.arbitrary_point().subs(t, S.Half))
False
>>> p.encloses_point(Point(5, 5))
False
Measure of the exterior angles.
Returns: | exterior_angle : number |
---|
Examples
>>> from sympy.geometry import RegularPolygon, Point
>>> rp = RegularPolygon(Point(0, 0), 4, 8)
>>> rp.exterior_angle
pi/4
The incircle of the RegularPolygon.
Returns: | incircle : Circle |
---|
See also
Examples
>>> from sympy.geometry import RegularPolygon, Point
>>> rp = RegularPolygon(Point(0, 0), 4, 7)
>>> rp.incircle
Circle(Point(0, 0), 4*cos(pi/7))
Alias for apothem.
Examples
>>> from sympy import Symbol
>>> from sympy.geometry import RegularPolygon, Point
>>> radius = Symbol('r')
>>> rp = RegularPolygon(Point(0, 0), radius, 4)
>>> rp.inradius
sqrt(2)*r/2
Measure of the interior angles.
Returns: | interior_angle : number |
---|
Examples
>>> from sympy.geometry import RegularPolygon, Point
>>> rp = RegularPolygon(Point(0, 0), 4, 8)
>>> rp.interior_angle
3*pi/4
Returns the length of the sides.
The half-length of the side and the apothem form two legs of a right triangle whose hypotenuse is the radius of the regular polygon.
Examples
>>> from sympy.geometry import RegularPolygon
>>> from sympy import sqrt
>>> s = square_in_unit_circle = RegularPolygon((0, 0), 1, 4)
>>> s.length
sqrt(2)
>>> sqrt((_/2)**2 + s.apothem**2) == s.radius
True
Radius of the RegularPolygon
This is also the radius of the circumscribing circle.
Returns: | radius : number or instance of Basic |
---|
Examples
>>> from sympy import Symbol
>>> from sympy.geometry import RegularPolygon, Point
>>> radius = Symbol('r')
>>> rp = RegularPolygon(Point(0, 0), radius, 4)
>>> rp.radius
r
Override GeometryEntity.reflect since this is not made of only points.
>>> from sympy import RegularPolygon, Line
>>> RegularPolygon((0, 0), 1, 4).reflect(Line((0, 1), slope=-2))
RegularPolygon(Point(4/5, 2/5), -1, 4, acos(3/5))
Override GeometryEntity.rotate to first rotate the RegularPolygon about its center.
>>> from sympy import Point, RegularPolygon, Polygon, pi
>>> t = RegularPolygon(Point(1, 0), 1, 3)
>>> t.vertices[0] # vertex on x-axis
Point(2, 0)
>>> t.rotate(pi/2).vertices[0] # vertex on y axis now
Point(0, 2)
CCW angle by which the RegularPolygon is rotated
Returns: | rotation : number or instance of Basic |
---|
Examples
>>> from sympy import pi
>>> from sympy.geometry import RegularPolygon, Point
>>> RegularPolygon(Point(0, 0), 3, 4, pi).rotation
pi
Override GeometryEntity.scale since it is the radius that must be scaled (if x == y) or else a new Polygon must be returned.
>>> from sympy import RegularPolygon
Symmetric scaling returns a RegularPolygon:
>>> RegularPolygon((0, 0), 1, 4).scale(2, 2)
RegularPolygon(Point(0, 0), 2, 4, 0)
Asymmetric scaling returns a kite as a Polygon:
>>> RegularPolygon((0, 0), 1, 4).scale(2, 1)
Polygon(Point(2, 0), Point(0, 1), Point(-2, 0), Point(0, -1))
Increment in place the virtual Polygon’s rotation by ccw angle.
See also: rotate method which moves the center.
>>> from sympy import Polygon, Point, pi
>>> r = Polygon(Point(0,0), 1, n=3)
>>> r.vertices[0]
Point(1, 0)
>>> r.spin(pi/6)
>>> r.vertices[0]
Point(sqrt(3)/2, 1/2)
The vertices of the RegularPolygon.
Returns: | vertices : list
|
---|
See also
Examples
>>> from sympy.geometry import RegularPolygon, Point
>>> rp = RegularPolygon(Point(0, 0), 5, 4)
>>> rp.vertices
[Point(5, 0), Point(0, 5), Point(-5, 0), Point(0, -5)]
A polygon with three vertices and three sides.
Parameters: | points : sequence of Points keyword: asa, sas, or sss to specify sides/angles of the triangle : |
---|---|
Raises: | GeometryError :
|
See also
Examples
>>> from sympy.geometry import Triangle, Point
>>> Triangle(Point(0, 0), Point(4, 0), Point(4, 3))
Triangle(Point(0, 0), Point(4, 0), Point(4, 3))
Keywords sss, sas, or asa can be used to give the desired side lengths (in order) and interior angles (in degrees) that define the triangle:
>>> Triangle(sss=(3, 4, 5))
Triangle(Point(0, 0), Point(3, 0), Point(3, 4))
>>> Triangle(asa=(30, 1, 30))
Triangle(Point(0, 0), Point(1, 0), Point(1/2, sqrt(3)/6))
>>> Triangle(sas=(1, 45, 2))
Triangle(Point(0, 0), Point(2, 0), Point(sqrt(2)/2, sqrt(2)/2))
Attributes
vertices | |
altitudes | |
orthocenter | |
circumcenter | |
circumradius | |
circumcircle | |
inradius | |
incircle | |
medians | |
medial |
The altitudes of the triangle.
An altitude of a triangle is a segment through a vertex, perpendicular to the opposite side, with length being the height of the vertex measured from the line containing the side.
Returns: | altitudes : dict
|
---|
Examples
>>> from sympy.geometry import Point, Triangle
>>> p1, p2, p3 = Point(0, 0), Point(1, 0), Point(0, 1)
>>> t = Triangle(p1, p2, p3)
>>> t.altitudes[p1]
Segment(Point(0, 0), Point(1/2, 1/2))
The angle bisectors of the triangle.
An angle bisector of a triangle is a straight line through a vertex which cuts the corresponding angle in half.
Returns: | bisectors : dict
|
---|
Examples
>>> from sympy.geometry import Point, Triangle, Segment
>>> p1, p2, p3 = Point(0, 0), Point(1, 0), Point(0, 1)
>>> t = Triangle(p1, p2, p3)
>>> from sympy import sqrt
>>> t.bisectors()[p2] == Segment(Point(0, sqrt(2) - 1), Point(1, 0))
True
The circumcenter of the triangle
The circumcenter is the center of the circumcircle.
Returns: | circumcenter : Point |
---|
See also
Examples
>>> from sympy.geometry import Point, Triangle
>>> p1, p2, p3 = Point(0, 0), Point(1, 0), Point(0, 1)
>>> t = Triangle(p1, p2, p3)
>>> t.circumcenter
Point(1/2, 1/2)
The circle which passes through the three vertices of the triangle.
Returns: | circumcircle : Circle |
---|
See also
Examples
>>> from sympy.geometry import Point, Triangle
>>> p1, p2, p3 = Point(0, 0), Point(1, 0), Point(0, 1)
>>> t = Triangle(p1, p2, p3)
>>> t.circumcircle
Circle(Point(1/2, 1/2), sqrt(2)/2)
The radius of the circumcircle of the triangle.
Returns: | circumradius : number of Basic instance |
---|
See also
Examples
>>> from sympy import Symbol
>>> from sympy.geometry import Point, Triangle
>>> a = Symbol('a')
>>> p1, p2, p3 = Point(0, 0), Point(1, 0), Point(0, a)
>>> t = Triangle(p1, p2, p3)
>>> t.circumradius
sqrt(a**2/4 + 1/4)
The center of the incircle.
The incircle is the circle which lies inside the triangle and touches all three sides.
Returns: | incenter : Point |
---|
See also
Examples
>>> from sympy.geometry import Point, Triangle
>>> p1, p2, p3 = Point(0, 0), Point(1, 0), Point(0, 1)
>>> t = Triangle(p1, p2, p3)
>>> t.incenter
Point(-sqrt(2)/2 + 1, -sqrt(2)/2 + 1)
The incircle of the triangle.
The incircle is the circle which lies inside the triangle and touches all three sides.
Returns: | incircle : Circle |
---|
See also
Examples
>>> from sympy.geometry import Point, Triangle
>>> p1, p2, p3 = Point(0, 0), Point(2, 0), Point(0, 2)
>>> t = Triangle(p1, p2, p3)
>>> t.incircle
Circle(Point(-sqrt(2) + 2, -sqrt(2) + 2), -sqrt(2) + 2)
The radius of the incircle.
Returns: | inradius : number of Basic instance |
---|
See also
Examples
>>> from sympy.geometry import Point, Triangle
>>> p1, p2, p3 = Point(0, 0), Point(4, 0), Point(0, 3)
>>> t = Triangle(p1, p2, p3)
>>> t.inradius
1
Are all the sides the same length?
Returns: | is_equilateral : boolean |
---|
See also
sympy.geometry.entity.GeometryEntity.is_similar, RegularPolygon, is_isosceles, is_right, is_scalene
Examples
>>> from sympy.geometry import Triangle, Point
>>> t1 = Triangle(Point(0, 0), Point(4, 0), Point(4, 3))
>>> t1.is_equilateral()
False
>>> from sympy import sqrt
>>> t2 = Triangle(Point(0, 0), Point(10, 0), Point(5, 5*sqrt(3)))
>>> t2.is_equilateral()
True
Are two or more of the sides the same length?
Returns: | is_isosceles : boolean |
---|
See also
Examples
>>> from sympy.geometry import Triangle, Point
>>> t1 = Triangle(Point(0, 0), Point(4, 0), Point(2, 4))
>>> t1.is_isosceles()
True
Is the triangle right-angled.
Returns: | is_right : boolean |
---|
See also
sympy.geometry.line.LinearEntity.is_perpendicular, is_equilateral, is_isosceles, is_scalene
Examples
>>> from sympy.geometry import Triangle, Point
>>> t1 = Triangle(Point(0, 0), Point(4, 0), Point(4, 3))
>>> t1.is_right()
True
Are all the sides of the triangle of different lengths?
Returns: | is_scalene : boolean |
---|
See also
Examples
>>> from sympy.geometry import Triangle, Point
>>> t1 = Triangle(Point(0, 0), Point(4, 0), Point(1, 4))
>>> t1.is_scalene()
True
Is another triangle similar to this one.
Two triangles are similar if one can be uniformly scaled to the other.
Parameters: | other: Triangle : |
---|---|
Returns: | is_similar : boolean |
Examples
>>> from sympy.geometry import Triangle, Point
>>> t1 = Triangle(Point(0, 0), Point(4, 0), Point(4, 3))
>>> t2 = Triangle(Point(0, 0), Point(-4, 0), Point(-4, -3))
>>> t1.is_similar(t2)
True
>>> t2 = Triangle(Point(0, 0), Point(-4, 0), Point(-4, -4))
>>> t1.is_similar(t2)
False
The medial triangle of the triangle.
The triangle which is formed from the midpoints of the three sides.
Returns: | medial : Triangle |
---|
See also
Examples
>>> from sympy.geometry import Point, Triangle
>>> p1, p2, p3 = Point(0, 0), Point(1, 0), Point(0, 1)
>>> t = Triangle(p1, p2, p3)
>>> t.medial
Triangle(Point(1/2, 0), Point(1/2, 1/2), Point(0, 1/2))
The medians of the triangle.
A median of a triangle is a straight line through a vertex and the midpoint of the opposite side, and divides the triangle into two equal areas.
Returns: | medians : dict
|
---|
Examples
>>> from sympy.geometry import Point, Triangle
>>> p1, p2, p3 = Point(0, 0), Point(1, 0), Point(0, 1)
>>> t = Triangle(p1, p2, p3)
>>> t.medians[p1]
Segment(Point(0, 0), Point(1/2, 1/2))
The orthocenter of the triangle.
The orthocenter is the intersection of the altitudes of a triangle. It may lie inside, outside or on the triangle.
Returns: | orthocenter : Point |
---|
See also
Examples
>>> from sympy.geometry import Point, Triangle
>>> p1, p2, p3 = Point(0, 0), Point(1, 0), Point(0, 1)
>>> t = Triangle(p1, p2, p3)
>>> t.orthocenter
Point(0, 0)
The triangle’s vertices
Returns: | vertices : tuple
|
---|
See also
Examples
>>> from sympy.geometry import Triangle, Point
>>> t = Triangle(Point(0, 0), Point(4, 0), Point(4, 3))
>>> t.vertices
(Point(0, 0), Point(4, 0), Point(4, 3))