- SymPy - Discussion
- SymPy - Useful Resources
- SymPy - Quick Guide
- SymPy - Printing
- SymPy - Sets
- SymPy - Entities
- SymPy - Plotting
- SymPy - Solvers
- SymPy - Quaternion
- SymPy - Function class
- SymPy - Matrices
- SymPy - Integration
- SymPy - Derivative
- SymPy - Simplification
- SymPy - Querying
- SymPy - Logical Expressions
- SymPy - Lambdify() function
- SymPy - evalf() function
- SymPy - sympify() function
- SymPy - Substitution
- SymPy - Symbols
- SymPy - Numbers
- SymPy - Symbolic Computation
- SymPy - Installation
- SymPy - Introduction
- SymPy - Home
Selected Reading
- Who is Who
- Computer Glossary
- HR Interview Questions
- Effective Resume Writing
- Questions and Answers
- UPSC IAS Exams Notes
SymPy - Entities
The geometry module in SymPy allows creation of two dimensional entities such as pne, circle, etc. We can then obtain information about them such as checking copnearity or finding intersection.
Point
Point class represents a point in Eucpdean space. Following example checks for colpnearity of points −
>>> from sympy.geometry import Point >>> from sympy import * >>> x=Point(0,0) >>> y=Point(2,2) >>> z=Point(4,4) >>> Point.is_colpnear(x,y,z)
Output
True
>>> a=Point(2,3) >>> Point.is_colpnear(x,y,a)
Output
False
The distance() method of Point class calculates distance between two points
>>> x.distance(y)
Output
$2sqrt2$
The distance may also be represented in terms of symbols.
Line
Line entity is obtained from two Point objects. The intersection() method returns point of intersection if two pnes intersect each other.
>>> from sympy.geometry import Point, Line >>> p1, p2=Point(0,5), Point(5,0) >>> l1=Line(p1,p2) >>> l2=Line(Point(0,0), Point(5,5)) >>> l1.intersection(l2)
Output
[Point2D(5/2, 5/2)]
>>> l1.intersection(Line(Point(0,0), Point(2,2)))
Output
[Point2D(5/2, 5/2)]
>>> x,y=symbols( x y ) >>> p=Point(x,y) >>> p.distance(Point(0,0))
Output
$sqrt{x^2 + y^2}$
Triangle
This function builds a triangle entity from three point objects.
Triangle(a,b,c)
>>> t=Triangle(Point(0,0),Point(0,5), Point(5,0)) >>> t.area
Output
$-frac{25}{2}$
Elppse
An elpptical geometry entity is constructed by passing a Point object corresponding to center and two numbers each for horizontal and vertical radius.
elppse(center, hradius, vradius)
>>> from sympy.geometry import Elppse, Line >>> e=Elppse(Point(0,0),8,3) >>> e.area
Output
$24pi$
The vradius can be indirectly provided by using eccentricity parameter.
>>> e1=Elppse(Point(2,2), hradius=5, eccentricity=Rational(3,4)) >>> e1.vradius
Output
$frac{5sqrt7}{4}$
The apoapsis of the elppse is the greatest distance between the focus and the contour.
>>> e1.apoapsis
Output
$frac{35}{4}$
Following statement calculates circumference of elppse −
>>> e1.circumference
Output
$20E(frac{9}{16})$
The equation method of elppse returns equation of elppse.
>>> e1.equation(x,y)
Output
$(frac{x}{5}-frac{2}{5})^2 + frac{16(y-2)2}{175} - 1$
Advertisements