网创优客建站品牌官网
为成都网站建设公司企业提供高品质网站建设
热线:028-86922220
成都专业网站建设公司

定制建站费用3500元

符合中小企业对网站设计、功能常规化式的企业展示型网站建设

成都品牌网站建设

品牌网站建设费用6000元

本套餐主要针对企业品牌型网站、中高端设计、前端互动体验...

成都商城网站建设

商城网站建设费用8000元

商城网站建设因基本功能的需求不同费用上面也有很大的差别...

成都微信网站建设

手机微信网站建站3000元

手机微信网站开发、微信官网、微信商城网站...

建站知识

当前位置:首页 > 建站知识

python三角函数图像 python绘制三角函数图像

如何用python表示三角函数

在python中,有一个math module,你可以import math,里面有math.sin(), math.cos(), math.asin()和math.acos()四个函数。相信你也知道asin和acos的意思,就是arcsin和arccos。有了这四个函数你就可以求函数值和角度了。但是要注意括号里面填的数值,要用弧度制。

成都创新互联成立于2013年,先为富裕等服务建站,富裕等地企业,进行企业商务咨询服务。为富裕企业网站制作PC+手机+微官网三网同步一站式服务解决您的所有建站问题。

简单python语言编程:采用自顶向下设计方法编写程序:在屏幕上打印三角函数y = sin(x)的图像。

I just wrote an simple one for one other guy.

You may check it here and see if it's useful for you.

如何用python完成:用自顶向下设计方法编写程序:在屏幕上打印三角函数y = sin(x)的图像。

I wrote this in Tkinter for you, in case you don't know Tkinter, it is a built-in module for most python versions.

If you want a commandline version, you can ask me, but tell you what, since those values are all

float numbers, so it's hard to get a precise graph in commandline window.

Well, in this version, I enlarged each element's position by 40 and then change them to integer, guess this is an endurable loss of precision.

#

from math import radians

from math import sin

from Tkinter import *

pos = []

xPos = 0

centerX = 0

centerY = 0

for deg in range(-360, 361, 10):

pos.append([xPos, int(40*(sin(radians(deg))))]) #1000 too big for my screen

xPos+=1

if deg == 0:

centerX = xPos-1

centerY = pos[-1][1]

root = Tk()

root.title('trianble graph from -180 to 180')

width, height = 550, 450

mHei = height/2

mWid = width/2

canvas = Canvas(root, width=width, height=height)

canvas.create_line(0, mHei, width, mHei)   #x axis

canvas.create_line(mWid, 0, mWid, height)  #y axis

xStep = (width-150)/len(pos)

yStep = (height-150)/len(pos)

radius = 3

# the middle point (sin(0) is first drawn and used as position reference for all

canvas.create_oval(mWid-radius, mHei-radius, mWid+radius, mHei+radius, fill='green')

print pos

print xStep, yStep, centerX, centerY

#exit(0)

for i in pos:

if i[0] == centerX: #center processed already.

continue

x = mWid + xStep*(i[0]-centerX)

# y is smaller, the bigger the value, so use minus

y = mHei - yStep*(i[1]-centerY)

canvas.create_oval(x-radius, y-radius, x+radius, y+radius, fill='green')

canvas.pack()

root.mainloop()


本文题目:python三角函数图像 python绘制三角函数图像
浏览地址:http://bjjierui.cn/article/dopcscd.html

其他资讯