I'm trying to implement my first class, partly as a way to break up the modeling and solving of a math problem I'm having trouble with. I don't think my problem relates to the class, but...?
The error keeps telling me that: "NameError: global name 'corner2' is not defined"
I tried moving the function call, but it still doesn't recognize it, so I put it back into the list declaration in my init function.
Here is my code:
class RotatedRectangle(object):
def corner1(a,b):
a/=2
b/=2
x=(a-b)*math.sin(math.pi/4)
y=(a+b)*math.sin(math.pi/4)
return (x,y)
def corner2(a,b):
a/=-2
b/=2
x=(a-b)*math.sin(math.pi/4)
y=(a+b)*math.sin(math.pi/4)
return (x,y)
def corner3(a,b):
a/=-2
b/=-2
x=(a-b)*math.sin(math.pi/4)
y=(a+b)*math.sin(math.pi/4)
return (x,y)
def corner4(a,b):
a/=2
b/=2
x=(a-b)*math.sin(math.pi/4)
y=(a+b)*math.sin(math.pi/4)
return (x,y)
def __init__(self, a, b,):
"""Return a Rotated rectangle object whose name is a function of a and b."""
self.name = str(a) + "," + str(b) + "-rectangle"
self.corners = [corner1(a,b), corner2(a,b), corner3(a,b), corner4(a,b)]
"""A rectangle with sides equal to even integers a and b is drawn on the Cartesian plane.Its center (the intersection point of its diagonals) coincides with the point (0, 0),but the sides of the rectangle are not parallel to the axes; instead, they are forming 45 degree angles with the axes.
How many points with integer coordinates are located inside the given rectangle (including on its sides)? """