0% found this document useful (0 votes)
40 views14 pages

Python Prac6

Uploaded by

ghalmenikhil
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
40 views14 pages

Python Prac6

Uploaded by

ghalmenikhil
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

Name: Rohit Vaman Kudande

Class: [Link]

Div: B

Roll No: 58

Date: 19/04/2023

MATH PRACTICAL-6(python)

**Convex Polygon**
Python3

>>> from sympy import *

>>> p1=Point(1,0)

>>> p2=Point(0,1)

>>> p3=Point(-1,0)

>>> p4=Point(0,-1)

>>> P=Polygon(p1,p2,p3,p4)

>>> P

Polygon(Point2D(1, 0), Point2D(0, 1), Point2D(-1, 0), Point2D(0, -1))

>>> P=Polygon(p1,p2,p3)

>>> P

Triangle(Point2D(1, 0), Point2D(0, 1), Point2D(-1, 0))

>>> Q=Polygon(Point(1,1),Point(-1,1),Point(-1,-1),Point(1,-1))

>>> Q

Polygon(Point2D(1, 1), Point2D(-1, 1), Point2D(-1, -1), Point2D(1, -1))

>>> P

Triangle(Point2D(1, 0), Point2D(0, 1), Point2D(-1, 0))

>>> Q

Polygon(Point2D(1, 1), Point2D(-1, 1), Point2D(-1, -1), Point2D(1, -1))

>>> p1,p2,p3,p4=[(2,0),(0,2),(-2,0),(0,-2)]
>>> R=Polygon(p1,p2,p3,p4)

>>> R

Polygon(Point2D(2, 0), Point2D(0, 2), Point2D(-2, 0), Point2D(0, -2))

** Regular Polygon With given center, radius & [Link] sides**

>>> S=RegularPolygon((0,0),1,4)

>>> S

RegularPolygon(Point2D(0, 0), 1, 4, 0)

**Function Releted to polygon**

>>> T=Triangle(p1,p2,p3)

>>> T

Triangle(Point2D(2, 0), Point2D(0, 2), Point2D(-2, 0))

>>> P=Polygon(p1,p2)

>>> P

Segment2D(Point2D(2, 0), Point2D(0, 2))

>>> P=Polygon(p1)

>>> P

Point2D(2, 0)

**Function Releted to polygon & Triangle**


1) Area Of Polygon:
>>> p1=Point(1,1)

>>> p2=Point(-1,1)

>>> p3=Point(-1,-1)

>>> p4=Point(1,-1)
>>> P=Polygon(p1,p2,p3,p4)

>>> P

Polygon(Point2D(1, 1), Point2D(-1, 1), Point2D(-1, -1), Point2D(1, -1))

>>> Q=Polygon(p1,p2,p3)

>>> Q

Triangle(Point2D(1, 1), Point2D(-1, 1), Point2D(-1, -1))

>>> R=RegularPolygon((1,2),4,10)

>>> R

RegularPolygon(Point2D(1, 2), 4, 10, 0)

>>> q1,q2,q3,q4=[(2,0),(0,2),(-2,0),(0,-2)]

>>> Q=Polygon(q1,q2,q3,q4)

>>> Q

Polygon(Point2D(2, 0), Point2D(0, 2), Point2D(-2, 0), Point2D(0, -2))

>>> S=Triangle(p1,p2,p3)

>>> S

Triangle(Point2D(1, 1), Point2D(-1, 1), Point2D(-1, -1))

>>> [Link]

>>> [Link]

>>> [Link]

5*(-2 + 2*sqrt(5))**2/(2*sqrt(1 - 2*sqrt(5)/5))

>>> [Link]

** Angles Of vertices**

>>> [Link][p1]
pi/2

>>> [Link][p2]

pi/2

>>> [Link][p3]

pi/2

>>> [Link][p4]

pi/2

>>>

>>> [Link][Point(0,2)]

pi/2

>>> [Link][p1]

pi/4

>>> [Link][p2]

pi/2

>>> [Link][p3]

pi/4

** To check Convex or Not**

>>> P.is_convex()

True

>>> P

Polygon(Point2D(1, 1), Point2D(-1, 1), Point2D(-1, -1), Point2D(1, -1))

>>> 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))

>>> [Link][p1]

pi/4

>>> [Link][p2]

pi/2

>>> [Link][p3]

pi/2

>>> [Link][p4]

pi/4

>>> [Link][p5]

3*pi/2

>>> P.is_convex()

False

** Perimeter of Polygon Or Triangle**

>>> [Link]

2*sqrt(2) + 6

>>> [Link]
-4 + 4*sqrt(5) + 8*sqrt(6 - 2*sqrt(5)) + 8*sqrt(-sqrt(5 - sqrt(5))*sqrt(sqrt(5) + 5) + 6)

>>> [Link]

2*sqrt(2) + 4

** Center of Regular Polygon**

>>> [Link]

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

Polygon(Point2D(1, 1), Point2D(-1, 1), Point2D(-1, -1), Point2D(1, -1))

>>> x,y=symbols('x,y')

>>> l=Line(x+y-1)

>>> l

Line2D(Point2D(0, 1), Point2D(1, 0))

>>> [Link](l)

Polygon(Point2D(0, 0), Point2D(0, 2), Point2D(2, 2), Point2D(2, 0))

** Rotation**
>>> [Link](pi/2)
Polygon(Point2D(-1, 1), Point2D(-1, -1), Point2D(1, -1), Point2D(1, 1))

>>> [Link](pi/4)

Polygon(Point2D(0, sqrt(2)), Point2D(-sqrt(2), 0), Point2D(0, -sqrt(2)), Point2D(sqrt(2), 0))

** Scaling **
>>> [Link](2,3)

Polygon(Point2D(2, 3), Point2D(-2, 3), Point2D(-2, -3), Point2D(2, -3))

** Some Terminologi **
>>> T1=Triangle(sss=(1,1,1))

>>> T1

Triangle(Point2D(0, 0), Point2D(1, 0), Point2D(1/2, sqrt(3)/2))

>>> T2=Triangle(sss=(3,4,5))

>>> T2

Triangle(Point2D(0, 0), Point2D(3, 0), Point2D(3, 4))

>>> T3=Triangle(sas=(3,90,4))

>>> T3

Triangle(Point2D(0, 0), Point2D(4, 0), Point2D(0, 3))

>>> T4=Triangle(asa=(30,10,45))

>>> T4

Triangle(Point2D(0, 0), Point2D(10, 0), Point2D(15 - 5*sqrt(3), -5 + 5*sqrt(3)))

>>>

>>>

>>> 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

Polygon(Point2D(0, 0), Point2D(1, 0), Point2D(2, 2), Point2D(1, 4))

>>> [Link]

1 + sqrt(17) + 2*sqrt(5)

>>> [Link]
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)

>>> [Link]

24*sqrt(2)

>>> [Link]

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)

>>> [Link]

(64 - 32*sqrt(2))/(-4 + 4*sqrt(2))

>>> [Link]

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)

>>> [Link](L)

RegularPolygon(Point2D(12/5, -34/5), -6, 7, -2*pi/7 + atan(4/3))

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

Polygon(Point2D(0, 0), Point2D(-2, 0), Point2D(5, 5), Point2D(1, -6))

>>> [Link](pi)

Polygon(Point2D(0, 0), Point2D(2, 0), Point2D(-5, -5), Point2D(-1, 6))

>>> [Link][p1]

acos(-sqrt(37)/37)

>>> [Link][p2]

-acos(7*sqrt(74)/74) + 2*pi

>>> [Link][p3]

-acos(83*sqrt(10138)/10138) + 2*pi

>>> [Link][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

Triangle(Point2D(1, 1), Point2D(2, -3), Point2D(-1, 5))

>>> x,y=symbols('x,y')

>>> l=Line(y+3)

>>> l

Line2D(Point2D(0, -3), Point2D(1, -3))

>>> [Link](l)

Triangle(Point2D(1, -7), Point2D(2, -3), Point2D(-1, -11))

Q-7) Rotate the triangle ABC by an angle 90 degree ,where A[1,-2],B[4,-6],C[-1,4]?



>>> from sympy import *

>>> A=Point(1,-2)

>>> B=Point(4,-6)

>>> C=Point(-1,4)

>>> T=Triangle(A,B,C)

>>> T

Triangle(Point2D(1, -2), Point2D(4, -6), Point2D(-1, 4))

>>> [Link](pi/2)

Triangle(Point2D(2, 1), Point2D(6, 4), Point2D(-4, -1))

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

Triangle(Point2D(0, 1), Point2D(-5, 0), Point2D(3, -3))

>>> [Link]

23/2

>>> [Link]

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

Triangle(Point2D(1, 1), Point2D(1, 2), Point2D(0, 1))

>>> [Link][A]

pi/2

>>> [Link][B]

pi/4

>>> [Link][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

Triangle(Point2D(-1, 0), Point2D(2, -1), Point2D(1, 3))

>>> x,y=symbols('x,y')

>>> l=Line(-x+y-3)

>>> [Link](l)

Triangle(Point2D(-3, 2), Point2D(-4, 5), Point2D(0, 4))

Q-11) Rotate the triangle ABC by 270 degree ,where A[-1,2],B[2,-5],C[-1,7]?



>>> A=Point(-1,2)

>>> B=Point(2,-5)

>>> C=Point(-1,7)

>>> T=Triangle(A,B,C)

>>> T

Triangle(Point2D(-1, 2), Point2D(2, -5), Point2D(-1, 7))

>>> [Link](3*pi/2)

Triangle(Point2D(2, 1), Point2D(-5, -2), Point2D(7, 1))

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))

>>> [Link]

-13/2

>>> [Link]

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

Triangle(Point2D(1, 0), Point2D(2, 3), Point2D(0, -2))

>>> [Link][P]

acos(-7*sqrt(2)/10)

>>> [Link][Q]

acos(17*sqrt(290)/290)

>>> [Link][R]

acos(12*sqrt(145)/145)

You might also like