Given:
Two vertices of an equilateral trainable as A,B ∊ RN when N > 1.
Goal:
Find the third vertex Z ∊ RN in which ||A-B|| = ||A-Z|| = ||B-Z||
.
I have the following python script from here which calculates it for 2-dimensional points (A,B ∊ R2 and Z ∊ R2):
import numpy as np
def equilateral(A, B):
# Computes `x coordinate` of the third vertex.
vx = ( A[0] + B[0] + np.sqrt(3) * ( A[1] - B[1] ) ) / 2
# Computes 'y coordinate' of the third vertex.
vy = ( A[1] + B[1] + np.sqrt(3) * ( A[0] - B[0] ) ) / 2
z = np.array([vx, vy]) #This point z is the third vertex.
return z
# Test for 2D vectors:
A = np.array([2,0])
B = np.array([5,0])
Z = equilateral(A,B)
print(z) # [ 3.5, -2.59807621]
How can I extend this (or maybe come up with more intelligent) solution to obtain the third vertex of N-dimensional vector such as the following test example?
N = 5
A = np.random.normal(size=(N, ))
B = np.random.normal(size=(N, ))
z = equilateral(A, B)
Cheers,