# Point - &amp;quot&amp;quot&amp;quot;Scales the...

This preview shows pages 1–2. Sign up to view the full content.

from math import sqrt # needed for computing distances class Point: """A coordinate system with (x, y) standards""" def __init__(self, initialX=0, initialY=0): """Let's the user input values for x and y; will default to 0 otherwise""" self._x = initialX self._y = initialY def getX(self): """Returns X value of Point""" return self._x def setX(self, val): """Sets the X value of Point""" self._x = val def getY(self): """Returns Y value of Point""" return self._y def setY(self, val): """Sets the Y value of Point""" self._y = val def scale(self, factor): """Multiplies the X and Y value by the inputted factor""" self._x *= factor self._y *= factor def distance(self, other): """Uses the distance formula to find the distance between current Point and another Point""" dx = self._x - other._x dy = self._y - other._y return sqrt(dx * dx + dy * dy) # imported from math module def normalize(self):

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: &amp;quot;&amp;quot;&amp;quot;Scales the Point from the Origin&amp;quot;&amp;quot;&amp;quot; mag = self.distance( Point() ) if mag &amp;gt; 0: self.scale(1/mag) def __str__(self): &amp;quot;&amp;quot;&amp;quot;Allows the user to see the coordinates of Point as &amp;lt;x,y&amp;gt;&amp;quot;&amp;quot;&amp;quot; return '&amp;lt;' + str(self._x) + ',' + str(self._y) + '&amp;gt;' def __add__(self, other): &amp;quot;&amp;quot;&amp;quot;Creates a new point as a result from adding X values and Y values together&amp;quot;&amp;quot;&amp;quot; return Point(self._x + other._x, self._y + other._y) def __mul__(self, operand): &amp;quot;&amp;quot;&amp;quot;Multiplies the coordinates if operand is constant; will use dot product if operand is another Point&amp;quot;&amp;quot;&amp;quot; if isinstance(operand, (int,float)): # multiply by constant return Point(self._x * operand, self._y * operand) elif isinstance(operand, Point): # dot product return self._x * operand._x + self._y * operand._y def __rmul__(self, operand): &amp;quot;&amp;quot;&amp;quot;Multiples the coordinates by operand&amp;quot;&amp;quot;&amp;quot; return self * operand...
View Full Document

## This note was uploaded on 05/03/2011 for the course CSCI 150 taught by Professor Staff during the Spring '08 term at Saint Louis.

### Page1 / 2

Point - &amp;quot&amp;quot&amp;quot;Scales the...

This preview shows document pages 1 - 2. Sign up to view the full document.

View Full Document
Ask a homework question - tutors are online