Help! Finding a point on a line program

Please support our Python advertiser: Programming Forums - DaniWeb Sister Site
Reply

Join Date: Jul 2008
Posts: 10
Reputation: Mazille is an unknown quantity at this point 
Solved Threads: 0
Mazille Mazille is offline Offline
Newbie Poster

Help! Finding a point on a line program

 
0
  #1
Jul 13th, 2008
I get an error when trying to make this program.

  1.  
  2. from pointLine import *
  3.  
  4. def calcSlope(x1,y1, x2,y2):
  5. slope = (x2-x1)/(y2-y1)
  6. return slope
  7.  
  8. def calcPointOnLine(y, m, x, b):
  9. if y == (m*x)+ b:
  10. return True
  11. else:
  12. return False
  13.  
  14. print "Point is on a Line? Program"
  15.  
  16. line1 = [(1,7), (7,19)]
  17. x1 = line1[0][0]
  18. x2 = line1[1][0]
  19. y1 = line1[0][1]
  20. y2 = line1[1][1]
  21.  
  22. slope1 = calcSlope(x1,y1,x2,y2)
  23. yIntercept = y1 - (((y2 - y1)/(x2 - x1))(x1))
  24.  
  25. p1 = Point(3,11)
  26. pointY1 = p1.y
  27. pointX1 = p1.x
  28.  
  29. print "Point(3,11) is on line", line1, ":", \
  30. calcPointOnLine(pointY1, slope1, pointX1, yIntercept)
  31.  
  32. p2 = Point(4,11)
  33. pointX2 = p2.x
  34. pointY2 = p2.y
  35.  
  36. print "Point(4,11) is on line", line1, ":", \
  37. calcPointOnLine (pointY2, slope1, pointX2, yIntercept)

Here's the dreaded error message:

  1. Traceback (most recent call last):
  2. File "C:\Users\Me\assignment.py", line 22, in <module>
  3. yIntercept = y1 - (((y2 - y1)/(x2 - x1))(x1))
  4. TypeError: 'int' object is not callable
Last edited by Mazille; Jul 13th, 2008 at 10:23 pm.
Reply With Quote Quick reply to this message  
Join Date: Mar 2007
Posts: 110
Reputation: solsteel is on a distinguished road 
Solved Threads: 31
solsteel solsteel is offline Offline
Junior Poster

Re: Help! Finding a point on a line program

 
1
  #2
Jul 14th, 2008
It appears that you omitted an operator:
yIntercept = y1 - (((y2 - y1)/(x2 - x1))(add operator here)(x1))
Reply With Quote Quick reply to this message  
Join Date: Jul 2008
Posts: 1,067
Reputation: jlm699 is a jewel in the rough jlm699 is a jewel in the rough jlm699 is a jewel in the rough jlm699 is a jewel in the rough 
Solved Threads: 267
Sponsor
jlm699's Avatar
jlm699 jlm699 is offline Offline
Knows where his Towel is

Re: Help! Finding a point on a line program

 
0
  #3
Jul 14th, 2008
Originally Posted by Mazille View Post
yIntercept = y1 - (((y2 - y1)/(x2 - x1))(x1))[/code]
Yes, Python is not a scientific calculator so it does not know that (x-5)(x-4) has an assumed multiplication between parenthesis. You will need to be more specific so change your line to
  1. yIntercept = y1 - ( ( ( y2 - y1 ) / ( x2 - x1 ) ) * ( x1 ) )
1. Use Code Tags.
2. Homework? Show Effort.
3. Keep discussions on the forum: no PMs
Reply With Quote Quick reply to this message  
Join Date: Jul 2008
Posts: 10
Reputation: Mazille is an unknown quantity at this point 
Solved Threads: 0
Mazille Mazille is offline Offline
Newbie Poster

Re: Help! Finding a point on a line program

 
0
  #4
Jul 16th, 2008
ohhh I forgot about that!!
I actually had copied and pasted that statement.
Thank you very much solsteel and jlm699!
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:



Similar Threads
Other Threads in the Python Forum
Thread Tools Search this Thread



Tag cloud for Python
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC