Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

PYTHON PROGRAMMING . class Vector3D: def __init__(self, x, y, z): # TODO: Create a routine that saves the vector # into this Vector3D object. pass

PYTHON PROGRAMMING

.

image text in transcribedimage text in transcribedimage text in transcribedimage text in transcribedimage text in transcribed

class Vector3D: def __init__(self, x, y, z): # TODO: Create a routine that saves the vector # into this Vector3D object. pass def __add__(self, other): # TODO: Create a routine that adds this vector with Vector3D other # and returns the result as a Vector3D object return None

def __neg__(self): # TODO: Create a routine that returns the negative (opposite) of # this vector as a Vector3D object

return None

def __sub__(self, other): # TODO: Create a routine that subtracts this vector with Vector3D other # and returns the result as a Vector3D object return None

def __mul__(self, other): # TODO: Create a routine that multiplies this vector with other # depending on its data type, and returns the result as a # Vector3D object. other can either be an integer # scalar or a Vector3D object.

return None

def main(): testcases = int(input())

for t in range(testcases): line_in = input().split() op = line_in[0].strip() vec_vals = [int(x) for x in line_in[1:]]

# TODO: a Write routine that processes a line in the input # op - string # - operation to do with the provided vectors # - can only be one from the set: {add, sub, neg, mul_s, mul} # vec_vals - list of integers # - numbers that follow the op in the input line # - can only have a length of 3, 4, or 6

if __name__ == '__main__': main()

3D graphic design is a relatively new but exciting field, especially with the advent of the metaverse and virtual reality. However, before the current advancements came into existence, somebody had to study the underlying "hard" math and implement everything into a computer. The basic unit of a 3D graphic is a 3D point or vector A, which is a tuple of three numbers (az , Qy, ay). Such a tuple represents a location in 3D space, which can additionally be interpreted as a vector pointing from the origin (0,0,0) to A. Being a contributor for the Numeric library in Python in the late 1990s, you took on the task to implement a 3D vector and its basic operations. More specifically, you will be implementing a class Vector3D that contains three integer coordinates, and supports the following operations: vector addition (add) subtraction (sub) negation (neg) element-wise multiplication (mul) scalar multiplication (mul_s). This Vector3D can be initialized by providing the 3D coordinates as such: Vector3D(x, y, z). In addition, you are required to write Vector3D in terms of special functions so that programmers could more expressively write their code. For example, if you have two 3D vectors a and b, programmers should be able to write a + b (the same as a. __add__(b)) in their programs. For testing purposes, you have generated a file containing a list of operations to execute and the operands to use, which can either be a 3D vector or scalar depending on the operation. a. Input Format The first line of the input is an integer T denoting the number of lines that will follow. Each line then consists of a variable number of elements separated by a space. The line starts with a word op denoting what operation to do. The operations will only be any of the following: add, sub, neg, mul_s, mul. The next elements will be space-separated numbers. For add, sub, and mul, op will be followed by six numbers at Uy az be by 6, corresponding to the coordinates of vectors a and b respectively. For mul_s. op will be followed by four numbers at Oy, Q, s corresponding to the coordinates of the vector a and a scalar 3. respectively. For neg, op will be followed by three numbers Qiz Oy A., corresponding to the coordinates of the vector a. Constraints = 5 Input Constraints T into this Vector3D object. 7 pass 8 def _add__(self, other): 10 # TODO: Create a routine that adds this vector with Vector3D other 11 and returns the result as a Vector3D object 12 13 14 15 def __nes__(self): 16 # TODO: Create a routine that returns the negative (opposite) of 17 # this vector as a Vector3D object 18 19 return None 20 21 def __sub__(self, other): 22 # TODO: Create a routine that subtracts this vector with Vector3D other 23 and returns the result as a Vector3D object 24 25 26 27 def __mul__(self, other): 28 # TODO: Create a routine that multiplies this vector with other 29 depending on its data type, and returns the result as a 30 Vector3D object. other can either be an integer 31 scalar or a Vector3D object. 32 33 return None 34 return None = ww58 35 def main(): 36 testcases = int(input) 37 38 for t in range (testcases): 39 line_in = input().split() 40 op = line_in[@].stripo 41 vec_vals = (int(x) for x in line_in[1:]] 42 43 # TODO: a Write routine that processes a line in the input 44 - string 45 - operation to do with the provided vectors 46 can only be one from the set: {add, sub, neg, mul_s, mul} 47 # vec_vals list of integers 48 numbers that follow the op in the input line 49 can only have a length of 3, 4, or 6 50 51 vif - name __main__': 52 main() # OP # + ==

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Databases And Python Programming MySQL MongoDB OOP And Tkinter

Authors: R. PANNEERSELVAM

1st Edition

9357011331, 978-9357011334

More Books

Students also viewed these Databases questions

Question

What is a chart of accounts?

Answered: 1 week ago

Question

3. Where is the job to be accomplished?

Answered: 1 week ago