0% found this document useful (0 votes)
2 views

Miscelaneous Python 2

The document contains Python code for calculating the area and perimeter of triangle ABC with given vertices, applying transformations to a point, generating lines and triangles, and plotting various geometric shapes using Matplotlib. It includes calculations for right-angled triangles and visualizations for triangles, rectangles, polygons, and line segments. The code demonstrates the use of libraries such as NumPy and SymPy for mathematical operations and plotting.

Uploaded by

yashodapawar10
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views

Miscelaneous Python 2

The document contains Python code for calculating the area and perimeter of triangle ABC with given vertices, applying transformations to a point, generating lines and triangles, and plotting various geometric shapes using Matplotlib. It includes calculations for right-angled triangles and visualizations for triangles, rectangles, polygons, and line segments. The code demonstrates the use of libraries such as NumPy and SymPy for mathematical operations and plotting.

Uploaded by

yashodapawar10
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 5

# Area and perimeter of triangle ABC where A[0,0],B[5,0],C[3,3]

import numpy as np

from math import*

x=np.matrix([[0,0],[5,0],[3,3]])

x1=(x[0,0],x[1,0],x[2,0])

y1=(x[0,1],x[1,1],x[2,1])

a=sqrt((x[1,0]-x[0,0])**2+(x[1,1]-x[0,1])**2)

print(a)

b=sqrt((x[2,0]-x[0,0])**2+(x[2,1]-x[0,1])**2)

print(b)

c=sqrt((x[2,0]-x[1,0])**2+(x[2,1]-x[1,1])**2)

print(c)

# Perimeter of triangle

p=a+b+c

print(p)

# Area of a triangle

s=(a+b+c)/2

A=s*(s-a)*(s-b)*(s-c)

area=sqrt(A)

print(area)

# Apply the following transformations on point P[4,-2]

import numpy as np

x=np.matrix([4,-2])

# Reflection through x-axis

t1=np.matrix([[1,0],[0,-1]])
x=x*t1

print(x)

# Reflection through origin

t2=np.matrix([[-1,0],[0,-1]])

x=x*t2

print(x)

#Shearing in x and y axis by 2 and -3 units

t3=np.matrix([[1,-3],[2,1]])

x=x*t3

print(x)

#Rotation about origin by 57 degree

a=np.cos(57)

b=np.sin(57)

t4=np.matrix([[a,b],[-b,a]])

x=x*t4

print(x)

# Generate line passing through points (2,3)and (4,1) and find equation of line

from sympy import*

p=Point(2,3)

q=Point(4,1)

l=Line(p,q)

l.equation()

# Using python generate triangle with vertices A[0,0],B[4,0],[4,3] and check whether it is right angled

from numpy import*

from math import*


x=matrix([[0,0],[4,5],[4,2]])

x1=(x[0,0],x[1,0],x[2,0])

y1=(x[0,1],x[1,1],x[2,1])

a=sqrt((x[1,0]-x[0,0])**2+(x[1,1]-x[0,1])**2)

print(a)

b=sqrt((x[2,0]-x[0,0])**2+(x[2,1]-x[0,1])**2)

print(b)

c=sqrt((x[2,0]-x[1,0])**2+(x[2,1]-x[1,1])**2)

print(c)

if (b**2==a**2+c**2 or a**2==b**2+c**2 or c**2==a**2+b**2):

print("Triangle is right angled triangle")

else:

print("Triangle is not right angled triangle")

# Write python program to plot 2D x-axix,y-axis in black color . In the same digram, plot

Green triangle with vertices [5,4],[7,4],[6,6]

from matplotlib.pyplot import*

import numpy as np

x=np.matrix([[5,4],[7,4],[6,6]])

x1=(x[0,0],x[1,0],x[2,0],x[0,0])

y1=(x[0,1],x[1,1],x[2,1],x[0,1])

plot(x1,y1,label="Triangle",color="Green")

#Blue rectangle with vertices [2,2],[10,2],[10,8],[2,8]

from matplotlib.pyplot import*

import numpy as np

x=np.matrix([[2,2],[10,2],[10,8],[2,8]])
x1=(x[0,0],x[1,0],x[2,0],x[3,0],x[0,0])

y1=(x[0,1],x[1,1],x[2,1],x[3,1],x[0,1])

plot(x1,y1,label="Rectangle",color="blue")

# Red polygon with vertices [6,2],[10,4],[8,7],[4,8],[2,4]

from matplotlib.pyplot import*

from numpy import*

p=[-10,10]

q=[0,0]

plot(p,q)

plot(q,p)

x=matrix([[6,2],[10,4],[8,7],[4,8],[2,4]])

x1=(x[0,0],x[1,0],x[2,0],x[3,0],x[4,0],x[0,0])

y1=(x[0,1],x[1,1],x[2,1],x[3,1],x[4,1],x[0,1])

plot(x1,y1,label="Polygon",color="red")

grid()

# Isoscale triangle with vertices [0,0],[4,0],[2,4]

from matplotlib.pyplot import*

import numpy as np

x=np.matrix([[0,0],[4,0],[2,4]])

x1=(x[0,0],x[1,0],x[2,0],x[0,0])

y1=(x[0,1],x[1,1],x[2,1],x[0,1])

plot(x1,y1,label="Iso Triangle",color="orange")

# Using python rotate line segment by 180 degree having end points (1,0),(2,-1)

from matplotlib.pyplot import*

import numpy as np
x=np.matrix([[1,0],[2,-1]])

x1=(x[0,0],x[1,0])

y1=(x[0,1],x[1,1])

plot(x1,y1,label="Given Segment",color="orange")

a=np.cos(180)

b=np.sin(180)

t=np.matrix([[a,b],[-b,a]])

x=x*t

x1=(x[0,0],x[1,0])

y1=(x[0,1],x[1,1])

plot(x1,y1,label="Rotated Segment",color="red")

You might also like