如何用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://scgulin.cn/article/dopcscd.html