AttributeError:尝试在sympy中增加圆的X值时无法设置属性

2024-10-01 19:15:59 发布

您现在位置:Python中文网/ 问答频道 /正文

我很难创建一个简单的函数,用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

任何帮助都将不胜感激!在


Tags: 函数代码testreturndefdistancepointcenter
1条回答
网友
1楼 · 发布于 2024-10-01 19:15:59

无法分配变量circle.center.x,如果要移动圆,请使用translate函数:

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)

相关问题 更多 >

    热门问题