I have two points X = (x1,y1)
and Y=(x2,y2)
in the Cartesian plane. I need to find the third point Z = (x,y)
such that these three points make an equilateral triangle.
I'm calculating the Euclidean distance between two points using the following code sample:
def distance(points, i, j):
dx = points[i][0] - points[j][0]
dy = points[i][1] - points[j][1]
return math.sqrt(dx*dx + dy*dy)
In theory, I need to equate the distances of XZ
and YZ
to XY
.This gives us two possible answers and I need them both too. But I'm having a difficulty in initiating the point Z
in my code. Can someone please help me with this?
The following is a sample of what I tried.
L = [0, 6] #known two points
d= distance(points, L[0], L[1])
x = Symbol('x')
y = Symbol('y')
newpoint = x,y #coordintes of the third point of the triangle
f1 = distance(points, L[0], newpoint)
f2 = distance(points, L[1], newpoint)
print(nsolve((f1, f2), (x, y), (d,d)))
But this returns the following error:
File "/Users/*.py", line 99, in <module>
f1 = distance(points, L[0], newpoint)
File "/Users/*.py", line 36, in distance
dx = points[i][0] - points[j][0]
TypeError: list indices must be integers or slices, not tuple