A 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.
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()
Point2D(4*t + 1, 3*t)
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, Line3D
>>> 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)
>>> Line.are_concurrent(l1, l2, l3)
True
>>> l4 = Line(p2, p3)
>>> Line.are_concurrent(l2, l3, l4)
False
Return a tuple (xmin, ymin, xmax, ymax) representing the bounding rectangle for the geometric figure.
The coefficients (\(a\), \(b\), \(c\)) for \(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)
[Point2D(7, 7)]
>>> p4, p5 = Point(5, 0), Point(0, 3)
>>> l2 = Line(p4, p5)
>>> l1.intersection(l2)
[Point2D(15/8, 15/8)]
>>> p6, p7 = Point(0, 5), Point(2, 6)
>>> s1 = Segment(p6, p7)
>>> l1.intersection(s1)
[]
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
Point2D(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
Point2D(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(Point2D(2, 2), Point2D(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
(Point2D(0, 0), Point2D(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 point is the intersection of L and the line perpendicular to L that passes through P.
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)
Point2D(1/4, 1/4)
>>> p4, p5 = Point(10, 0), Point(12, 1)
>>> s1 = Segment(p4, p5)
>>> l1.projection(s1)
Segment(Point2D(5, 5), Point2D(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
Point2D(...)
>>> # 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(Point2D(2, 3), Point2D(3, 5))
>>> L.points
(Point2D(2, 3), Point2D(3, 5))
>>> L.equation()
-2*x + y + 1
>>> L.coefficients
(-2, 1, 1)
Instantiate with keyword slope:
>>> Line(Point(0, 0), slope=0)
Line(Point2D(0, 0), Point2D(1, 0))
Instantiate with another linear object
>>> s = Segment((0, 0), (0, 1))
>>> Line(s).equation()
x
Attributes
is_Complement | |
is_EmptySet | |
is_Intersection | |
is_UniversalSet |
Return True if o is on this Line, or False otherwise.
Examples
>>> from sympy import Line,Point
>>> p1, p2 = Point(0, 1), Point(3, 4)
>>> l = Line(p1, p2)
>>> l.contains(p1)
True
>>> l.contains((0, 1))
True
>>> l.contains((0, 0))
False
Finds the shortest distance between a line and a point.
Raises : | NotImplementedError is raised if o is not a Point |
---|
Examples
>>> from sympy import Point, Line
>>> p1, p2 = Point(0, 0), Point(1, 1)
>>> s = Line(p1, p2)
>>> s.distance(Point(-1, 1))
sqrt(2)
>>> s.distance((-1, 2))
3*sqrt(2)/2
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(Point2D(2, 3), Point2D(3, 5))
>>> r.points
(Point2D(2, 3), Point2D(3, 5))
>>> r.source
Point2D(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?
Examples
>>> from sympy import Ray,Point,Segment
>>> p1, p2 = Point(0, 0), Point(4, 4)
>>> r = Ray(p1, p2)
>>> r.contains(p1)
True
>>> r.contains((1, 1))
True
>>> r.contains((1, 3))
False
>>> s = Segment((1, 1), (2, 2))
>>> r.contains(s)
True
>>> s = Segment((1, 2), (2, 5))
>>> r.contains(s)
False
>>> r1 = Ray((2, 2), (3, 3))
>>> r.contains(r1)
True
>>> r1 = Ray((2, 2), (3, 5))
>>> r.contains(r1)
False
The direction in 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.direction
Point2D(4, 1)
Finds the shortest distance between the ray and a point.
Raises : | NotImplementedError is raised if o is not a Point |
---|
Examples
>>> from sympy import Point, Ray
>>> p1, p2 = Point(0, 0), Point(1, 1)
>>> s = Ray(p1, p2)
>>> s.distance(Point(-1, -1))
sqrt(2)
>>> s.distance((-1, 2))
3*sqrt(2)/2
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
Point2D(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(Point2D(1, 0), Point2D(1, 1))
>>> s = Segment(Point(4, 3), Point(1, 1))
>>> s
Segment(Point2D(1, 1), Point2D(4, 3))
>>> s.points
(Point2D(1, 1), Point2D(4, 3))
>>> s.slope
2/3
>>> s.length
sqrt(13)
>>> s.midpoint
Point2D(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)
>>> s.distance((0, 12))
sqrt(73)
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
Point2D(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(Point2D(3, 3), Point2D(9, -3))
>>> s1.perpendicular_bisector(p3)
Segment(Point2D(3, 3), Point2D(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]