You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

求助:可用Python Turtle绘制目标曲线的参数方程

三尖瓣线的参数方程与Python Turtle实现

你需要的曲线是三尖瓣线(Deltoid Curve),对应的参数方程如下(参数a控制曲线尺寸,可自行调整):

  • x = a*(2cosθ + cos2θ)
  • y = a*(2sinθ - sin2θ)
    θ的取值范围为0到2π。

以下是用Python Turtle绘制该曲线的完整代码:

import turtle
import math

# 配置参数
a = 100  # 控制曲线大小
step = 0.01  # 步长越小,曲线越平滑

# 初始化海龟绘图
pen = turtle.Turtle()
pen.speed(0)  # 设置最快绘制速度
pen.penup()

# 遍历参数θ绘制曲线
for i in range(int(2 * math.pi / step)):
    theta = i * step
    x = a * (2 * math.cos(theta) + math.cos(2 * theta))
    y = a * (2 * math.sin(theta) - math.sin(2 * theta))
    pen.goto(x, y)
    pen.pendown()

# 回到起点闭合曲线
pen.goto(a*(2+1), 0)

turtle.done()

调整a的值可以放大或缩小曲线,减小step能让曲线边缘更平滑。

内容的提问来源于stack exchange,提问作者chews

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.06 20:42:05