我正在嘗試撰寫一個函式equilateral(x, y):,它接受兩個np.ndarrays of shape (N,) ,其中 x 和 y 是自然數并回傳一個點 zan np.ndarray of shape (N,)使得 ( x , y , z ) 是等邊三角形的頂點。
任何一位請建議。
uj5u.com熱心網友回復:
為了獲得第三個頂點,您只需將點 (x2, y2,...) 圍繞點 (x1, y1,...) 旋轉 60 度。另一種可接受的解決方案將通過旋轉 -60 度(即,在相反方向上)獲得。
因此,只需將 y 圍繞 x 旋轉 60/-60 度,您就擁有了第三個坐標。
uj5u.com熱心網友回復:
您可以使用以下程式實作此目的。您還可以擴展代碼以測驗點之間的距離是否相等。
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
轉載請註明出處,本文鏈接:https://www.uj5u.com/net/331464.html
上一篇:有人可以幫我理解這段代碼嗎?
