在VB中,我已知很多xy坐标,要根据这些坐标拟合画出一条直线,应该是怎么样一个语句呢?谢谢~~在线等,高分相赠

解决方案 »

  1.   

    简单点可以用贝塞尔曲线函数
    Private Declare Function PolyBezier Lib "gdi32" (ByVal hdc As Long, lppt As POINTAPI, ByVal cPoints As Long) As Long
      

  2.   

    我想要的是画出这条直线的语句。就是类似picture1.pset.....后面该是什么呢?
      

  3.   

    再一个建议,用picture1.line 或polyline函数,将这些点连起来,如果用pset的形式就是
    picture1.PSet (x, y), vbRed '用红色绘点
    我认为用picture1.line比较好,pset只能绘出离散的点。
      

  4.   

    你应该将多点座标的X及Y值赋值给变量X及Y的数组,然后使用
    Option Explicit
        Dim x(500) As Single
        Dim y(500) As Single
        Dim i As Integer
    Private Sub Command1_Click()
        For i = 0 To 500
            Picture1.PSet (x(i), y(i))
        Next
    End Sub
      

  5.   

    我这儿有现成的,自己看看,仅供参考:
    http://topic.csdn.net/u/20080515/09/f47e3407-7944-4cf5-9179-6722a02ffa8e.html
      

  6.   

    给你写个代码,自己研究研究:
    Dim x1 As Integer
    Dim y1 As Integer
    Dim IsStart As BooleanPrivate Sub Form_Load()
    IsStart = False
    End SubPrivate Sub Form_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
    If Button = 1 Then
    IsStart = True
    x1 = X
    y1 = Y
    End If
    End SubPrivate Sub Form_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
    If IsStart = True And Button = 1 Then
    Form1.Cls
    Form1.Line (x1, y1)-(X, Y)
    End If
    End SubPrivate Sub Form_MouseUp(Button As Integer, Shift As Integer, X As Single, Y As Single)
    If Button = 1 Then
    Form1.Line (x1, y1)-(X, Y)
    IsStart = False
    End If
    End Sub
      

  7.   

    使用polyline或polylineto API函数
      

  8.   

    还可以使用PolyPolyLine直接将线段连成一个多边线。
      

  9.   

    能说的详细点吗?我不会API函数
      

  10.   

    您好,我不是要用MOUSEmove等事件,我的XY坐标值是算出来的,现在需要将这些离散的点拟合成直线,得出该直线的斜率
      

  11.   

    VB6示例代码:
    Private Declare Function Polyline Lib "gdi32" (ByVal hdc As Long, lpPoint As POINTAPI, ByVal nCount As Long) As Long
    Private Type POINTAPI
            x As Long
            y As Long
    End TypeDim pts(1 To 4) As POINTAPIPrivate Sub Form_Load()
        Me.AutoRedraw = True
        Me.ScaleMode = vbPixels
        '以下是随便写的点的坐标
        pts(1).x = 10
        pts(1).y = 10
        
        pts(2).x = 20
        pts(2).y = 20
        
        pts(3).x = 10
        pts(3).y = 20
        
        pts(4).x = 40
        pts(4).y = 50
        '将点连接起来
        Polyline Me.hdc, pts(1), 4
    End Sub