我想繪製圖像中繪製一個傾斜的橢圓。但是,我不確定如何定義它,因爲雖然下面的方案會移動點,但我認爲這隻會擠壓橢圓,而不是旋轉它(也是我認爲在任何情況下都存在某種程度上的錯誤)。我將該函數的輸出提供給橢圓命令並將其添加到現有圖片,因此任何會旋轉整個圖像的方法都不好。 OD只是我使用的座標中心的平方偏移量。如何在ImageDraw中繪製一個傾斜的橢圓?
def ellipsebound(major, minor, tilt=0, offset=0, angle=0):
#creates a bound for an ellispe, defined with tilt meaning to rotate the orthogonal axis and angle corresponds to rotating the ellipse position
angle = radians(angle)
tilt = radians(tilt)
box=(
1 + int(ceil((OD+offset*cos(angle)+(major*cos(tilt)+minor*sin(tilt)))/conv)),
1 + int(ceil((OD+offset*sin(angle)+(major*sin(tilt)-minor*cos(tilt)))/conv)),
int(ceil((2*OD-(OD-offset*cos(angle)-(major*cos(tilt)+minor*sin(tilt)))/conv))),
int(ceil((2*OD-(OD-offset*sin(angle)-(major*sin(tilt)-minor*cos(tilt)))/conv)))
) #create bounding box
return box
有誰知道如何做到這一點?
您應該只需要半大小,半微小,中心點和一個角度來完全描述橢圓。不知道爲什麼你有額外的角度(角度和傾斜度),除非你繪製了一個扁平的橢圓,這實際上並不是一個橢圓。 – John
那,並檢查這個問題。 http://stackoverflow.com/questions/87734/how-do-you-calculate-the-axis-aligned-bounding-box-of-an-ellipse – John
橢圓所在的座標系是極座標。偏移和角度移動橢圓的中心點(相對於PIL座標中的offset = 0(OD,OD)),而主要,次要和傾斜控制着它的形狀。 – Elliot