我正在尝试编写一个函数 equiside(x, y):
,它需要两个形状为 (N,) 的 np.ndarrays
,其中 x 和 y 是自然的数字并返回点 z 形状为 (N,)
的 np.ndarray,使得 (x, y, z) 是等边三角形的顶点。
请推荐任何一个。
最佳答案
您可以使用以下程序来实现此目的。 您还可以将代码扩展为测试,如果点之间的距离相等。
import numpy as np
def equilateral(x, y):
v_x = (x[0]+y[0]+np.sqrt(3)*(x[1]-y[1]))/2 # This computes the `x coordinate` of the third vertex.
v_y = (x[1]+y[1]+np.sqrt(3)*(x[0]-y[0]))/2 #This computes the 'y coordinate' of the third vertex.
z = np.array([v_x, v_y]) #This is point z, the third vertex.
return z
关于Python函数求等边三角形的一点,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/69671976/