For this lab you will create a custom class that implements a point in 3-D space. Name your class 'pt3d'. The class will
Posted: Fri May 20, 2022 5:58 pm
For this lab you will create a custom class that implements a point in 3-D space. Name your class 'pt3d'.
The class will have three attributes, x,y,z. These x,y,z values should default to zero.
Given two instances of the pt3d class a and b, implement methods such that:
a+b returns a new pt3d object whose x, y and z values are the sum of the a and b x, y and z values
a-b returns the Euclidean distance between points a and b
a==b returns true if the x, y and z values of a and b are equal, false otherwise
When you call print(a) the printout should be of the format '<a.x,a.y,a.z>'
You can test and develop your class either from the main block in your program, from another module, or using the python interpreter directly:
>>> from pt3d import pt3d
>>> p1=pt3d(1,1,1)
>>> p2=pt3d(2,2,2)
>>> print(p1+p2)
<3,3,3>
>>> print(p1-p2)
1.7320508075688772
>>> p1==p2
False
>>> p1+p1==p2
True
>>> p1==p2+pt3d(-1,-1,-1)
True
`
LAB ACTIVITY 11.26. 1:3-D point class 0/10 pt3d.py Load fandt lass ptsd: class implementation goes here Develop mode Submit mode Run your program as often as you'd like, before submitting for grading Below, type any needed input values in the fust box then click Run program and observe the programmis output in the second box
The class will have three attributes, x,y,z. These x,y,z values should default to zero.
Given two instances of the pt3d class a and b, implement methods such that:
a+b returns a new pt3d object whose x, y and z values are the sum of the a and b x, y and z values
a-b returns the Euclidean distance between points a and b
a==b returns true if the x, y and z values of a and b are equal, false otherwise
When you call print(a) the printout should be of the format '<a.x,a.y,a.z>'
You can test and develop your class either from the main block in your program, from another module, or using the python interpreter directly:
>>> from pt3d import pt3d
>>> p1=pt3d(1,1,1)
>>> p2=pt3d(2,2,2)
>>> print(p1+p2)
<3,3,3>
>>> print(p1-p2)
1.7320508075688772
>>> p1==p2
False
>>> p1+p1==p2
True
>>> p1==p2+pt3d(-1,-1,-1)
True
`
LAB ACTIVITY 11.26. 1:3-D point class 0/10 pt3d.py Load fandt lass ptsd: class implementation goes here Develop mode Submit mode Run your program as often as you'd like, before submitting for grading Below, type any needed input values in the fust box then click Run program and observe the programmis output in the second box