0% found this document useful (0 votes)
6 views4 pages

Practical No. 5

The document contains a series of Python programming exercises focused on geometric shapes using the SymPy library. It includes tasks such as drawing polygons, rotating shapes, calculating areas and perimeters, and checking triangle properties. Each exercise is accompanied by code snippets and their respective outputs.
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)
6 views4 pages

Practical No. 5

The document contains a series of Python programming exercises focused on geometric shapes using the SymPy library. It includes tasks such as drawing polygons, rotating shapes, calculating areas and perimeters, and checking triangle properties. Each exercise is accompanied by code snippets and their respective outputs.
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
You are on page 1/ 4

Practical No.

Q.1

Write a Python program to draw a polygon with vertices (0,0), (2,0), (2,3), and
(1,6) and rotate it by 180°

In [13]:

from sympy import *


A = Point(0,0)
B = Point(2,0)
C = Point(2,3)
D = Point(1,6)
p = Polygon(A,B,C,D)

print(p.rotate(pi))

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

Q.2

In [32]:

from sympy import *


A = Point(1,1)
B = Point(2,-2)
C = Point(1,2)
p = Polygon(A,B,C) # also we can use p = Triangle(A,B,C)

print(p.rotate(pi/2))

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


Q.3

Write a Python program to find the area and perimeter of the ∆ABC, where
A[0,0], B[6,0], and C[4,4].

In [16]:

from sympy import *


A = Point(0,0)
B = Point(6,0)
C = Point(4,4)
p = Polygon(A,B,C)

print('Perimeter of traingle is : ', p.perimeter)


print('Area of traingle is : ', p.area)

Perimeter of traingle is : 2*sqrt(5) + 4*sqrt(2) + 6


Area of traingle is : 12

Q.4

Using Python, draw a regular polygon with 6 sides and radius 1 centered at
(1,2) and find its area and perimeter.

In [19]:

from sympy import *


p = Polygon(Point(1,2),1,n=6)

print('Perimeter of Polygon is : ', p.perimeter)


print('Area of Polygon is : ', p.area)

Perimeter of Polygon is : 6
Area of Polygon is : 3*sqrt(3)/2
Q.5

Write a Python program to plot the rectangle with vertices at [2,1], [2,4] [5,4],
[5,1] and its uniform expansion by factor 4.

In [28]:

from sympy import *


A = Point(2,1)
B = Point(2,4)
C = Point(5,4)
D = Point(5,1)
p = Polygon(A,B,C,D)

print(p.scale(4,4)) # unifome scaling in both x and y direction

Polygon(Point2D(8, 4), Point2D(8, 16), Point2D(20, 16), Point2D(20, 4))

Q.6

Generate a triangle with vertices (0,0), (4,0), and (1,4), and check whether the
triangle is a Scalene triangle.

In [31]:

from sympy import *


A = Point(0,0)
B = Point(4,0)
C = Point(4,3)
p = Polygon(A,B,C) # also we can use p = Triangle(A,B,C)

print(p.is_scalene())

True

#Conclusion - Given polygon(Triangle) is scalene


Q.7

In [35]:

from sympy import *


A = Point(0,0)
B = Point(4,0)
C = Point(4,3)
p = Polygon(A,B,C)

print(p.angles[A])
print(p.angles[B])
print(p.angles[C]) # Note - here we used sqaure bracket for angles

acos(4/5)
pi/2
acos(3/5)

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy