Practical 5
Practical 5
2.3 Lines
In [22]: 1 #Two points that lie on the same line are said to be collinear points
2 #Line, L passing through the points(2,3) and (4,3) is defined as follow
3
4 L = Line(Point(2,3), Point(4,3))
Out[22]: Line2D(Point2D(2,3),Point2D(4,3))
In [24]: 1 #The line corresponding to an equation in the form of ax + by + c = 0 c
2 #Line having equation 2x+3y=4:
3 P = Line(2*x + 3*y - 4 )
4 P
Out[24]:
Line2D(Point2D(0, 43 ),Point2D(1, 23 ))
In [63]: 1 #The line with point and slope can be entered as follows:
2 #Line with Point (1, 4) and slope=1
3 B = Line(Point(1,4), slope = 1)
4 B
Out[63]: Line2D(Point2D(1,4),Point2D(2,5))
In [ ]: 1 #We can display equation and coefficients as follows:
In [64]: 1 B.equation()
Out[64]: −𝑥 + 𝑦 − 3
In [68]: 1 B.coefficient()
2
3 #ID and fix error later
--------------------------------------------------------------------------
-
AttributeError Traceback (most recent call las
t)
Cell In[68], line 1
----> 1 B.coefficient()
Line Segment
In [69]: 1 S = Segment((0,0),(0,1))
2 S
Out[69]: Segment2D(Point2D(0,0),Point2D(0,1))
Ray
In [70]: 1 r = Ray ((0,0), (2,3))
2 r
Out[70]: Ray2D(Point2D(0,0),Point2D(2,3))
Functions related to lines, segments and
rays:
1. Angle between rtwo linear entities(Lines, rays, segment): We can find angle formed by
intersection of linear entities using angle_between as follows
Out[73]: 0
In [75]: 1 # Angle between Ray r and Segment s
2 r.angle_between(s)
𝜋
4
Out[75]:
Out[76]: 𝜋
4
2. Intersection if points of two linear points:
Out[6]: []
In [7]: 1 """
2 from sympy import *
3
4 l = Line((0,8),(8,0))
5 s = Segment ((0,0),(10,10))
6 r = Ray((0,3),(3,0))
7 """
8
9 s.length
Out[7]: 10√⎯⎯2
In [9]: 1 l.length
Out[9]: ∞
In [10]: 1 r.length
Out[10]: ∞
4. Distance:
In [12]: 1 l.distance(p)
Out[12]: 6√⎯⎯2
In [13]: 1 s.distance(p)
Out[13]: 0
In [14]: 1 r.distance(p)
Out[14]: 17√⎯⎯2
2
5. Slope of the linear entities
Out[26]: 2
In [17]: 1 #from sympy import *
2 s = Segment ((1,0),(2,-1))
3 s.slope #Slope of Seg s
Out[17]: −1
In [19]: 1 #from sympy import *
2 r = Ray((0,0),(3,3))
3 r.slope #Slope of Ray r
Out[19]: 1
6. Midpoint of the segment:
Out[21]:
Point2D( 32 ,− 12 )
In [22]: 1 #from sympy import *
2 s = Segment ((3,2),(2,-3))
3 s.midpoint
Out[22]:
Point2D( 52 ,− 12 )
7. Point of linear entities:
--------------------------------------------------------------------------
-
NameError Traceback (most recent call las
t)
Cell In[1], line 3
1 #from sympy import *
2 #from math import *
----> 3 l = Line(x+y-5)
4 l.points()
In [33]: 1 r = Ray((0,0),(0,1))
2 r.points
In [41]: 1 l = Line((0,0),(0,1))
2 l.rotate(pi/6)
Out[41]:
Line2D(Point2D(0,0),Point2D(− 12 , 1000000000000000
866025403784439
))
In [43]: 1 #from sympy import *
2 a = l.rotate(pi/6)
3 a.equation()
Out[43]:
− 866025403784439𝑥 −
1000000000000000 2
𝑦
In [44]: 1 s = Segment((1,0),(2,-1))
2 s.rotate(pi)
24492935982947
Segment2D(Point2D(−1, 200000000000000000000000000000 ),Point2D(−2,1))
Out[44]:
In [45]: 1 r = Ray((0,0),(4,4))
2 r.rotate(pi/2)
Out[45]: Ray2D(Point2D(0,0),Point2D(−4,4))
In [46]: 1 r.rotate(-pi/2) #rotate by -90 degrees
Out[46]: Ray2D(Point2D(0,0),Point2D(4,−4))
In [47]: 1 r.rotate(pi) #rotate by 180 degrees
Out[47]: Ray2D(Point2D(0,0),Point2D(−4,−4))
9. Rotation of linear entities
Out[48]:
𝑥 + 4𝑦3 + 53
Ex: 2.12 Reflect the segment through two endpoints [(2,3),(4,6)] through line 7x+6y =
3
In [50]: 1
2 #from sympy import *
3 A = Point(2,3)
4 B = Point(4,6)
5
6 S = Segment(A, B)
7 x,y = symbols("x y")
8 l = Line(7*x + 6*y - 3)
9
10 #Reflection of "S" through "l"
11
12 S.reflect(l)
Out[50]:
Segment2D(Point2D(− 236 ,− 93 ,Point2D − 514 ,− 222
85 85 ) ( 85 85 ))
Ex: 2.13 Reflect the line segment having starting Point[(0,0)] in the direction of (2,4)
through line x - 2y = 3
In [9]: 1
2 from sympy import *
3 A = Point(0,0)
4 B = Point(2,4)
5
6 S = Ray(A, B)
7 x,y = symbols("x y")
8 l = Line(x - 2*y - 3)
9
10 #Reflection of Ray "S" through Line "l"
11
12 S.reflect(l)
Out[9]:
Ray2D(Point2D( 65 ,− 125 ),Point2D( 285 ,− 165 ))
10. Transformation of linear entities:
Ex. 2.14: If the line with points A[2 1] , B[4 -1] is transformed by the transformation
matrix, [T] = Matrix([[1,2],[2,1]]) , then find the equation of transformed line.
Out[6]: −2𝑥 − 2𝑦 + 18