Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Write a class called Vec 2 D . The required methods are shown in the code snippet below. The comment indicates the action of the
Write a class called VecD The required methods are shown in the code snippet below. The comment indicates the action of the method and what is returned.
A quick review of the dot product:
Take two vectors, each with Cartesian components x and y: a ax ay and b bx by The dot product of vectors a and b results in a scalar and is given by:
a b axbx ayby
class VecD:
def initself x y:
Store x and y in a form of your choosing."""
def strself:
Returns string of form x y
def reprself:
Returns string of form 'VecDx y
def getxself:
Getter for x Returns x
def getyself:
Getter for y Returns y
def setxself x:
Setter for x
def setyself y:
Setter for y
def addself b:
Vector addition of self and b Returns a VecD object."""
def subself b:
Vector subtraction: self b Returns a VecD object."""
def mulself scalar:
Multiplication on left of VecD and scalar: self scalar. Returns VecD
object."""
def rmulself scalar:
Multiplication on right of VecD and scalar: scalar self. Returns VecD
object."""
def lengthself:
Computes length of the vector. Returns a float."""
def dotself b:
Computes dot product of self and b Returns a float."""
Sample:
a VecD
a
VecD
printa
agetx
agety
b VecD
b
VecD
bsetx; bsety
b
VecD
c a b
c
VecD
d a b
d
VecD
a
VecD
b
VecD
clength
dlength
adotb
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started