Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/codeigniter/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python:使用math&;绘制切线图;海龟图书馆_Python_Math_Turtle Graphics - Fatal编程技术网

Python:使用math&;绘制切线图;海龟图书馆

Python:使用math&;绘制切线图;海龟图书馆,python,math,turtle-graphics,Python,Math,Turtle Graphics,我被这项任务耽搁了好几天。尽管如此,解决方案应该很简单。我应用数学和turtle库绘制了3个图形:振幅为200的正弦、余弦和切线。问题是我不能按照应该绘制的那样绘制切线图。 这是我应该做的: 这就是我得到的: 正如你所看到的,我的乌龟飞了起来,再也不回来了。 请不要建议我使用numpy。这不是我的任务。 谢谢你的预支 import math import turtle ws = turtle.Screen() ws.bgcolor("white") t = turtle.Turtle()

我被这项任务耽搁了好几天。尽管如此,解决方案应该很简单。我应用数学和turtle库绘制了3个图形:振幅为200的正弦、余弦和切线。问题是我不能按照应该绘制的那样绘制切线图。 这是我应该做的:

这就是我得到的:

正如你所看到的,我的乌龟飞了起来,再也不回来了。 请不要建议我使用numpy。这不是我的任务。 谢谢你的预支

import math
import turtle

ws = turtle.Screen()
ws.bgcolor("white")
t = turtle.Turtle()
for i in [(0,250), (0,0), (0,-250), (0,0), (400,0), (0,0)]:
    t.goto(i, None)
    t.write(i, font=("Arial", 12))

t.color("red")

for angle in range(360):
    y = math.sin(math.radians(angle))        
    t.goto(angle, y * 200)

t.penup()
t.setpos(0,200)
t.goto(0,200)
t.pendown()
t.color("blue")

for angle in range(360):
    y = math.cos(math.radians(angle))       
    t.goto(angle, y * 200)

t.penup()
t.setpos(0,0)
t.goto(0,0)
t.pendown()
t.color("green")

for angle in range(360):
    y = math.tan(math.radians(angle))
    t.goto(angle, y * 200)

ws.exitonclick()

为了说明它应该有效,下面是我使用海龟图形绘制正弦、余弦和切线的最简单实现:

import math
from turtle import Turtle, Screen

RESOLUTION = 0.1

def plot(x_points, y_points):
    for i, y in enumerate(y_points):
        if abs(y) <= 2.0:
            yertle.goto(x_points[i], y)
            yertle.pendown()
        else:
            yertle.penup()

    yertle.penup()

screen = Screen()
screen.setworldcoordinates(0, -1.5, 2 * math.pi / RESOLUTION, 1.5)

yertle = Turtle()
yertle.penup()

x = range(int(2 * math.pi / RESOLUTION))

yertle.color("blue")
plot(x, (math.cos(n * RESOLUTION) for n in x))

yertle.color("red")
plot(x, (math.sin(n * RESOLUTION) for n in x))

yertle.color("dark green")
plot(x, (math.tan(n * RESOLUTION) for n in x))

screen.exitonclick()
导入数学
从海龟进口海龟,屏幕
分辨率=0.1
def绘图(x_点、y_点):
对于枚举中的i,y(y_点):

如果abs(y)试试这个。快为我工作了,没有时间变得更好:

对于范围内的角度(360): y=0

y=math.tan(数学弧度(角度))
如果y-1:
t、 转到(角度,y*200)
带有asipmtotas

for angle in range(360):
    t.penup()
    y = math.tan(math.radians(angle))

    if y<1 and y>-1:
        t.pendown()
        t.goto(angle, y * 200)
    else:
        t.penup()
        #t.pendown()
        t.goto(angle, 200)
范围内的角度(360):
t、 彭普()
y=数学tan(数学弧度(角度))
如果y-1:
t、 彭敦()
t、 转到(角度,y*200)
其他:
t、 彭普()
#t、 彭敦()
t、 后藤(角度,200)

如果编辑此问题以包含无法产生正确结果的代码,将更容易提供帮助。是的,你是对的。谢谢你的评论!范围(360)内角度的
:y=0有什么作用?
for angle in range(360):
    t.penup()
    y = math.tan(math.radians(angle))

    if y<1 and y>-1:
        t.pendown()
        t.goto(angle, y * 200)
    else:
        t.penup()
        #t.pendown()
        t.goto(angle, 200)