Hi all. I'm working on a python file that will be included in a project I am working on. Unfortunately, I ran into some problems when it came to passing arguments from a function, to another function. Let me explain; I have two functions: dist and return_mouse_angle. dist returns the distance between two points, and return_mouse_angle returns the slope of two points...

def dist(p1,p2):
     # a^2 + b^2 = c^2
     return math.sqrt( (p2[0]-p1[0])^2+(p2[1]-p1[1])^2 )

def return_mouse_angle(mouse_pos,object_pos):
     radians = math.asin( dist(mouse_pos,object_pos)/
                          dist(mouse_pos,[mouse_pos[0],object_pos[1]]) )
     degress = math.degrees( radians )
     print degrees

for example, when I run

return_mouse_slope( [100,100],[154,129])

I get this error:

Traceback (most recent call last):
  File "<pyshell#59>", line 1, in <module>
    return_mouse_slope( [100,100],[154,129])
  File "C:/Documents and Settings/Owner/Desktop/rewrite project warp/lib/maths.py", line 15, in return_mouse_slope
    dist(mouse_pos,[mouse_pos[0],object_pos[1]]) )
ValueError: math domain error

I'm not able to pass mouse_pos[0] and object_pos[1] to the dist function. Is python not able to pass arguments (in this case, a list) from a function to another function?

Recommended Answers

All 3 Replies

Traceback (most recent call last):
  File "<pyshell#59>", line 1, in <module>
    return_mouse_slope( [100,100],[154,129])
  File "C:/Documents and Settings/Owner/Desktop/rewrite project warp/lib/maths.py", line 15, in return_mouse_slope
    dist(mouse_pos,[mouse_pos[0],object_pos[1]]) )
ValueError: math domain error

I'm not able to pass mouse_pos[0] and object_pos[1] to the dist function. Is python not able to pass arguments (in this case, a list) from a function to another function?

Try to figure out how to use the dist function in the interpreter and then implement it inside your function. The ValueError is telling you that what you're trying to do is unsupported by dist.

but how do i do that? i tried putting the dist function in return_mouse_angle:

def return_mouse_slope(mouse_pos,object_pos):
     p1 = mouse_pos
     p2 = object_pos
     p3 = [mouse_pos[0],object_pos[1]]
     # sin^-1 and distance formula
     radians = math.asin( math.sqrt( (p2[0]-p1[0])^2+(p2[1]-p1[1])^2 )/
                          math.sqrt( (p3[0]-p1[0])^2+(p3[1]-p1[1])^2 ) )

     degress = math.degrees( radians )
     print degrees

but I still got

Traceback (most recent call last):
  File "<pyshell#16>", line 1, in <module>
    return_mouse_slope([100,100],[50,150])
  File "C:\Documents and Settings\Owner\Desktop\rewrite project warp\lib\maths.py", line 18, in return_mouse_slope
    radians = math.asin( math.sqrt( (p2[0]-p1[0])^2+(p2[1]-p1[1])^2 )/
ValueError: math domain error

Try this:
print(10^2)
print(10**2)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.