VB系统的坐标原点在左上角,X轴的正方向是水平向右,而Y轴的正方向是垂直向下。所以,要绘制三角函数的曲线,自己可以通过改变点坐标的方法来实现,当然,VB.NET提供了相应的方法可以来实现坐标变换,也可以通过VB.Net的Graphics类提供的平移、旋转等转换来实现。
我们提供的服务有:成都网站设计、成都做网站、外贸网站建设、微信公众号开发、网站优化、网站认证、雷州ssl等。为上千多家企事业单位解决了网站和推广的问题。提供周到的售前咨询和贴心的售后服务,是有科学管理、有技术的雷州网站制作公司
下面是我通过自己变换实现的示例,提供参考;我的环境是VB.NET 2010
Imports System.Math
Public Class Form1
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
'1,获得一个Graphics对象
Dim MyGraphics As Graphics
MyGraphics = PictureBox1.CreateGraphics
'2,定义一个Pen对象,用于绘制图形(轮廓线)
Dim MyPen As New Pen(Color.Black, 1)
'3,定义一个Brush对象,用于填充图形(如果需要填充的话)
Dim MyBrush As New SolidBrush(Color.Orange)
MyGraphics.DrawLine(MyPen, 0, 200, 700, 200)
End Sub
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
'1,获得一个Graphics对象
Dim MyGraphics As Graphics
MyGraphics = PictureBox1.CreateGraphics
'2,定义一个Pen对象,用于绘制图形(轮廓线)
Dim MyPen As New Pen(Color.Black, 1)
'3,定义一个Brush对象,用于填充图形(如果需要填充的话)
Dim MyBrush As New SolidBrush(Color.Orange)
'声明横向和纵向比例变量
Dim Heng As Integer = 20
Dim Zong As Integer = 50
'先获得正弦值,保存到点坐标数组
Dim MyPoints(700) As Point
Dim i As Integer
For i = 0 To 700
MyPoints(i) = New Point(i * Heng, 200 + Sin(i) * Zong)
Next
'采用绘制光滑线连接点的方式绘制曲线
MyGraphics.DrawCurve(MyPen, MyPoints)
End Sub
End Class
显示的效果图:
第一步,新建一个工程,新建一个Form1,在上面添加一个picture控件和一个command控件,然后选中此控件,右击"复制",在窗体空白处右击"粘贴",在弹出的对话框中选择"是",创建了一个Command控件数组,复制,使窗体上总共出现7个Command控件,然后复制代码:
Const Pi = 3.1415926535 '定义圆周率
Dim a, wor
Dim i As Integer
Static Function Loge(X)
Loge = Log(X) / Log(Exp(1))
End Function
'定义用于在Picture1上的一个位置打印字符函数
Private Function PrintWord(X, y, Word As String)
With Picture1
.CurrentX = X
.CurrentY = y
.ForeColor = RGB(0, 0, 255)
End With
Picture1.Print Word
End Function
Private Function DrawDot(Px, Py, Color)
Picture1.PSet (Px, Py), Color
End Function
Sub XY() '建立直角坐标系
Picture1.DrawWidth = 1 '设置线条宽度
Picture1.Cls
'设定用户坐标系,坐标原点在Picture1中心
Picture1.Scale (-10, 10)-(10, -10)
Picture1.Line (-10, 0)-(10, 0), RGB(0, 0, 255)
Picture1.Line -(9.5, 0.5), RGB(0, 0, 255)
Picture1.Line (10, 0)-(9.5, -0.5), RGB(0, 0, 255)
Picture1.ForeColor = RGB(0, 0, 255)
Picture1.Print "X"
'画 X 轴
Picture1.Line (0, -10)-(0, 10), RGB(0, 0, 255)
Picture1.Line -(0.5, 9.5), RGB(0, 0, 255)
Picture1.Line (0, 10)-(-0.5, 9.5), RGB(0, 0, 255)
Picture1.Print "Y"
'画 Y 轴
For lin = -9 To 9
Picture1.Line (lin, 0)-(lin, 0.25)
wor = PrintWord(lin - 0.5, -0.5, Str(lin))
Picture1.Line (0, lin)-(-0.25, lin)
If lin 0 Then
wor = PrintWord(-0.9, lin, Str(lin))
End If
Next lin
Picture1.DrawWidth = 2
End Sub
Private Sub Command1_Click(Index As Integer)
Select Case Index
Case 0
For a = -3 To 3 Step Pi / 6000
Dot = DrawDot(a, a ^ 2, RGB(0, 0, 0))
Next a
wor = PrintWord(4, 9, "二次曲线 y=x^2")
Case 1
For a = -9 To 9 Step Pi / 6000
Dot = DrawDot(a, a, RGB(0, 0, 0))
Next a
wor = PrintWord(8, 5, "一次曲线 y=x")
Case 2
For a = -9 To 3 Step Pi / 6000
Dot = DrawDot(a, Exp(a), RGB(0, 0, 0))
Next a
wor = PrintWord(4, 9, "指数曲线 y=e^x")
Case 3
For a = 0.0001 To 9 Step Pi / 6000
Dot = DrawDot(a, Loge(a), RGB(0, 0, 0))
Next a
wor = PrintWord(8, 3, "对数曲线 y=ln x")
Case 4
For a = -10 To 10 Step Pi / 6000
Dot = DrawDot(a, Sin(a), RGB(0, 0, 0))
Next a
wor = PrintWord(-5, 2, "正弦曲线 y=sin x")
Case 5
For a = -10 To 10 Step Pi / 6000
Dot = DrawDot(a, Cos(a), RGB(0, 0, 0))
Next a
wor = PrintWord(-9, 2, "余弦曲线 y=cos x")
Case 6
XY
End Select
End Sub
Private Sub Form_Load()
Me.Caption = "数学函数作图?quot;"
Me.Show
Me.AutoRedraw = True
Picture1.AutoRedraw = True
Command1(0).Caption = "二次曲线"
Command1(1).Caption = "一次曲线"
Command1(2).Caption = "指数曲线"
Command1(3).Caption = "对数曲线"
Command1(4).Caption = "正弦曲线"
Command1(5).Caption = "余弦曲线"
Command1(6).Caption = "清空"
XY
End Sub
Private Sub Form_Resize()
Picture1.Width = Me.Width * 0.94
Picture1.Height = Me.Height - (Command1(0).Height * 4 + 100)
Command1(0).Top = Me.Height - (Command1(0).Height * 2.5 + 100)
Command1(0).Left = Me.Width * 0.01
For i = 1 To 6
Command1(i).Top = Me.Height - (Command1(0).Height * 2.5 + 100)
Command1(i).Left = Command1(i - 1).Left + 1000
Next
XY
End Sub
这问题有点笼统,软糖来说说把:
图像处理由System.Drawing命名空间负责。
主要是Bitmap类和Graphics类。
Bitmap表示一个位图,可以是BMP,JPG,PNG等文件。
装载位图
Dim 位图 As Bitmap = Bitmap.FromFile("C:\Image1.PNG")
Graphics表示一张画纸,能够进行绘制操作。
它可以被窗体、控件、位图调用CreateGraphics()方法来创建。
然后调用Graphics.Draw开头的一系列函数来绘制图像和图形,Fill开头的填充图形。
创建画纸并绘制位图
Dim 画纸 As Graphics = Me.CreateGraphics()
画纸.DrawImage(位图, 100, 100, 256, 256)
可以将上面三行放到Form1_Load中测试,把路径改一下,
还可以把Me改为能在上面绘图的控件的名称。
更多内容请看MSDN的System.Drawing命名空间。
如满意,请采纳,谢谢。