2017-03-07 24 views
0

創建一個簡單函數會使用sympy增加圓中心的X值,遇到很多麻煩。這裏是我的代碼:AttributeError:嘗試增加sympy中圓的X值時無法設置屬性

test_center=Point (1,2) 
test_circle = Circle (test_center, 1) 

def travel (circle, distance): 

    circle.center.x += distance 
    return circle.center.x 

travel (test_circle,1) 
print(test_circle) 

我能得到什麼回覆是:

線16條,在旅遊

circle.center.x += distance AttributeError: can't set attribute

任何幫助,將不勝感激!

+0

我希望你能接受標記的答案。 –

回答

1

變量circle.center.x不能分配,如果要移動的圈子使用翻譯功能:

from sympy import Point, Circle 

test_center=Point (1,2) 
test_circle = Circle (test_center, 1) 

def travel (circle, distance): 
    return circle.translate(x=distance) 


test_circle = travel(test_circle,1) 
print(test_circle) 
相關問題