Python Prac6
Python Prac6
Class: Sy.Bsc.cs
Div: B
Roll No: 58
Date: 19/04/2023
MATH PRACTICAL-6(python)
**Convex Polygon**
Python3
>>> p1=Point(1,0)
>>> p2=Point(0,1)
>>> p3=Point(-1,0)
>>> p4=Point(0,-1)
>>> P=Polygon(p1,p2,p3,p4)
>>> P
>>> P=Polygon(p1,p2,p3)
>>> P
>>> Q=Polygon(Point(1,1),Point(-1,1),Point(-1,-1),Point(1,-1))
>>> Q
>>> P
>>> Q
>>> p1,p2,p3,p4=[(2,0),(0,2),(-2,0),(0,-2)]
>>> R=Polygon(p1,p2,p3,p4)
>>> R
>>> S=RegularPolygon((0,0),1,4)
>>> S
RegularPolygon(Point2D(0, 0), 1, 4, 0)
>>> T=Triangle(p1,p2,p3)
>>> T
>>> P=Polygon(p1,p2)
>>> P
>>> P=Polygon(p1)
>>> P
Point2D(2, 0)
>>> p2=Point(-1,1)
>>> p3=Point(-1,-1)
>>> p4=Point(1,-1)
>>> P=Polygon(p1,p2,p3,p4)
>>> P
>>> Q=Polygon(p1,p2,p3)
>>> Q
>>> R=RegularPolygon((1,2),4,10)
>>> R
>>> q1,q2,q3,q4=[(2,0),(0,2),(-2,0),(0,-2)]
>>> Q=Polygon(q1,q2,q3,q4)
>>> Q
>>> S=Triangle(p1,p2,p3)
>>> S
>>> P.area
>>> Q.area
>>> R.area
>>> S.area
** Angles Of vertices**
>>> P.angles[p1]
pi/2
>>> P.angles[p2]
pi/2
>>> P.angles[p3]
pi/2
>>> P.angles[p4]
pi/2
>>>
>>> Q.angles[Point(0,2)]
pi/2
>>> S.angles[p1]
pi/4
>>> S.angles[p2]
pi/2
>>> S.angles[p3]
pi/4
>>> P.is_convex()
True
>>> P
>>> P=Polygon(p1,p2,p3,p4)
>>> p5=Point(0,0)
>>> p1
Point2D(1, 1)
>>> p2
Point2D(-1, 1)
>>> p3
Point2D(-1, -1)
>>> p4
Point2D(1, -1)
>>> p5
Point2D(0, 0)
>>> P=Polygon(p1,p2,p3,p4,p5)
>>> P
Polygon(Point2D(1, 1), Point2D(-1, 1), Point2D(-1, -1), Point2D(1, -1), Point2D(0, 0))
>>> P.angles[p1]
pi/4
>>> P.angles[p2]
pi/2
>>> P.angles[p3]
pi/2
>>> P.angles[p4]
pi/4
>>> P.angles[p5]
3*pi/2
>>> P.is_convex()
False
>>> P.perimeter
2*sqrt(2) + 6
>>> R.perimeter
-4 + 4*sqrt(5) + 8*sqrt(6 - 2*sqrt(5)) + 8*sqrt(-sqrt(5 - sqrt(5))*sqrt(sqrt(5) + 5) + 6)
>>> S.perimeter
2*sqrt(2) + 4
>>> R.center
Point2D(1, 2
** Reflection **
Q-1) Construct the polygon with vertices A(1,1),B(-1,1),C(-1,-1) and D(1,-1) reflect it through the line “
x+y=1”?
>>> from sympy import*
>>> A=Point(1,1)
>>> B=Point(-1,1)
>>> C=Point(-1,-1)
>>> D=Point(1,-1)
>>> P=Polygon(A,B,C,D)
>>> P
>>> x,y=symbols('x,y')
>>> l=Line(x+y-1)
>>> l
>>> P.reflect(l)
** Rotation**
>>> P.rotate(pi/2)
Polygon(Point2D(-1, 1), Point2D(-1, -1), Point2D(1, -1), Point2D(1, 1))
>>> P.rotate(pi/4)
** Scaling **
>>> P.scale(2,3)
** Some Terminologi **
>>> T1=Triangle(sss=(1,1,1))
>>> T1
>>> T2=Triangle(sss=(3,4,5))
>>> T2
>>> T3=Triangle(sas=(3,90,4))
>>> T3
>>> T4=Triangle(asa=(30,10,45))
>>> T4
>>>
>>>
>>> T1.is_isosceles()
True
>>> T1.is_right()
False
>>> T2.is_right()
True
>>> T3.is_right()
True
>>> T4.is_right()
False
>>>
>>>
>>> T1.is_scalene()
False
>>> T2.is_scalene()
True
>>> T3.is_scalene()
True
>>> T4.is_scalene()
True
Q-1) Draw a polygon with vertices (0,0),(1,0),(2,2),(1,4) and find its area and perimeter?
>>> p1=Point(0,0)
>>> p2=Point(1,0)
>>> p3=Point(2,2)
>>> p4=Point(1,4)
>>> P=Polygon(p1,p2,p3,p4)
>>> P
>>> P.perimeter
1 + sqrt(17) + 2*sqrt(5)
>>> P.area
4
Q-2) Draw a regular polygon with 4 sides and radius 6 centered at origin and find its area and
perimeter?
>>>S=RegularPolygon((0,0),6,4)
>>> S
RegularPolygon(Point2D(0, 0), 6, 4, 0)
>>> S.perimeter
24*sqrt(2)
>>> S.area
72
Q-3) Draw a regular polygon with 8 sides and radius 2 centered at (-1,2) and find its area and
perimeter?
>>>R=RegularPolygon((-1,2),2,8)
>>> R
RegularPolygon(Point2D(-1, 2), 2, 8, 0)
>>> R.area
>>> R.perimeter
16*sqrt(2 - sqrt(2))
Q-4) Draw a regular polygon with 7 sides and radius 6 centered at (-2,2) and reflect it through
line x-2y=5?
>>>A=RegularPolygon((-2,2),6,7)
>>> A
RegularPolygon(Point2D(-2, 2), 6, 7, 0)
>>> x,y=symbols('x,y')
>>> L=Line(x-2y=5)
>>> L=Line(x-2*y-5)
>>> A.reflect(L)
Q-5) Draw a polygon with vertices (0,0),(-2,0),(5,5) and (1,-6) and rotate by 180 degree and
find internal angle at each vertex?
>>>p1=Point(0,0)
>>> p2=Point(-2,0)
>>> p3=Point(5,5)
>>> p4=Point(1,-6)
>>> P=Polygon(p1,p2,p3,p4)
>>> P
>>> P.rotate(pi)
>>> P.angles[p1]
acos(-sqrt(37)/37)
>>> P.angles[p2]
-acos(7*sqrt(74)/74) + 2*pi
>>> P.angles[p3]
-acos(83*sqrt(10138)/10138) + 2*pi
>>> P.angles[p4]
-acos(62*sqrt(5069)/5069) + 2*pi
Q-6) Reflect the triangle ABC through the line y=-3 ,where A[1,1],B[2,-3],C[-1,5]?
>>> from sympy import *
>>> A=Point(1,1)
>>> B=Point(2,-3)
>>> C=Point(-1,5)
>>> T=Triangle(A,B,C)
>>> T
>>> x,y=symbols('x,y')
>>> l=Line(y+3)
>>> l
>>> T.reflect(l)
>>> A=Point(1,-2)
>>> B=Point(4,-6)
>>> C=Point(-1,4)
>>> T=Triangle(A,B,C)
>>> T
>>> T.rotate(pi/2)
Q-8) Find the area and perimeter of the triangle ABC,where A[0,1],B[-5,0],C[3,-3]?
>>> from sympy import *
>>> A=Point(0,1)
>>> B=Point(-5,0)
>>> C=Point(3,-3)
>>> T=Triangle(A,B,C)
>>> T
>>> T.area
23/2
>>> T.perimeter
5 + sqrt(26) + sqrt(73)
Q-9) Find the angle at each vertices of the triangle ABC,where A[1,1],B[1,2],C[0,1]?
>>> A=Point(1,1)
>>> B=Point(1,2)
>>> C=Point(0,1)
>>> T=Triangle(A,B,C)
>>> T
>>> T.angles[A]
pi/2
>>> T.angles[B]
pi/4
>>> T.angles[C]
pi/4
Q-10) Reflect the triangle ABC through the line y=x+3 ,where A[-1,0],B[2,-1],C[1,3]?
>>> A=Point(-1,0)
>>> B=Point(2,-1)
>>> C=Point(1,3)
>>> T=Triangle(A,B,C)
>>> T
>>> x,y=symbols('x,y')
>>> l=Line(-x+y-3)
>>> T.reflect(l)
>>> B=Point(2,-5)
>>> C=Point(-1,7)
>>> T=Triangle(A,B,C)
>>> T
>>> T.rotate(3*pi/2)
Q-12) Find the area and perimeter of the triangle ABC,where A[0,1],B[-5,0],C[-3,3]?
>>> from sympy import *
>>> A=Point(0,1)
>>> B=Point(-5,0)
>>> C=Point(-3,3)
>>> T=Triangle(A,B,C)
>>> T
Triangle(Point2D(0, 1), Point2D(-5, 0), Point2D(-3, 3))
>>> T.area
-13/2
>>> T.perimeter
sqrt(26) + 2*sqrt(13)
Q-13) Find the angle at each vertices of the triangle PQR,where P[1,0],Q[2,3],R[0,-2]?
>>> from sympy import *
>>> P=Point(1,0)
>>> Q=Point(2,3)
>>> R=Point(0,-2)
>>> T=Triangle(P,Q,R)
>>> T
>>> T.angles[P]
acos(-7*sqrt(2)/10)
>>> T.angles[Q]
acos(17*sqrt(290)/290)
>>> T.angles[R]
acos(12*sqrt(145)/145)