954,541 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

Help! Finding a point on a line program

I get an error when trying to make this program.

from pointLine import *

def calcSlope(x1,y1, x2,y2):
    slope = (x2-x1)/(y2-y1)
    return slope
    
def calcPointOnLine(y, m, x, b):
    if  y == (m*x)+ b:
        return True
    else:
        return False
    
print "Point is on a Line? Program"

line1 = [(1,7), (7,19)]
x1 = line1[0][0]
x2 = line1[1][0]
y1 = line1[0][1]
y2 = line1[1][1]

slope1 = calcSlope(x1,y1,x2,y2)
yIntercept = y1 - (((y2 - y1)/(x2 - x1))(x1))

p1 = Point(3,11)
pointY1 = p1.y
pointX1 = p1.x

print "Point(3,11) is on line", line1, ":", \
      calcPointOnLine(pointY1, slope1, pointX1, yIntercept)

p2 = Point(4,11)
pointX2 = p2.x
pointY2 = p2.y

print "Point(4,11) is on line", line1, ":", \
      calcPointOnLine (pointY2, slope1, pointX2, yIntercept)


Here's the dreaded error message:

Traceback (most recent call last):
  File "C:\Users\Me\assignment.py", line 22, in <module>
    yIntercept = y1 - (((y2 - y1)/(x2 - x1))(x1))
TypeError: 'int' object is not callable
Mazille
Newbie Poster
10 posts since Jul 2008
Reputation Points: 10
Solved Threads: 0
 

It appears that you omitted an operator:
yIntercept = y1 - (((y2 - y1)/(x2 - x1))(add operator here)(x1))

solsteel
Junior Poster
145 posts since Mar 2007
Reputation Points: 86
Solved Threads: 42
 
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

yIntercept = y1 - ( ( ( y2 - y1 ) / ( x2 - x1 ) ) * ( x1 ) )
jlm699
Veteran Poster
1,112 posts since Jul 2008
Reputation Points: 355
Solved Threads: 292
 

ohhh I forgot about that!!
I actually had copied and pasted that statement.
Thank you very much solsteel and jlm699!

Mazille
Newbie Poster
10 posts since Jul 2008
Reputation Points: 10
Solved Threads: 0
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You