Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/mysql/62.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
vb.net中的数据点旋转_Vb.net - Fatal编程技术网

vb.net中的数据点旋转

vb.net中的数据点旋转,vb.net,Vb.net,我有一个位置列表(x;y)要显示在带有角度旋转的图片框中 For Each pat As cPattern In mPattern Dim angle As Double = pat.Angle / 180 * Math.PI For Each pos As PointF In pat.Positions Dim p As Point = New Point(picPattern.Width \ 2, picPattern.Height \ 2)

我有一个位置列表(x;y)要显示在带有角度旋转的图片框中

For Each pat As cPattern In mPattern
    Dim angle As Double = pat.Angle / 180 * Math.PI

    For Each pos As PointF In pat.Positions
        Dim p As Point = New Point(picPattern.Width \ 2, picPattern.Height \ 2)

        Dim G As Graphics = e.Graphics

        Dim x1 As Single = CSng(pos.X * Math.Cos(angle))
        Dim y1 As Single = CSng(pos.Y * Math.Sin(angle))

        G.DrawEllipse(New Pen(Brushes.Cyan, 2), p.X+x1, p.Y-y1, 3, 3)

    Next
Next

使用此代码,我可以为每个位置绘制一个圆,但只能在水平模式下绘制。

如果要围绕图片框的中心旋转,请使用以下代码:

Private Sub picPattern_Paint(sender As Object, e As PaintEventArgs) Handles picPattern.Paint
    Dim G As Graphics = e.Graphics
    Dim center As Point = New Point(picPattern.Width \ 2, picPattern.Height \ 2)
    Using cyan As New Pen(Brushes.Cyan, 2)
        For Each pat As cPattern In mPattern
            G.ResetTransform()
            G.TranslateTransform(center.X, center.Y)
            G.RotateTransform(pat.angle) ' angle in DEGREES!
            For Each pos As PointF In pat.Positions
                Dim r As New Rectangle(pos.X, pos.Y, 1, 1)
                r.Inflate(3, 3)
                G.DrawEllipse(cyan, r)
            Next
        Next
    End Using
End Sub

听起来您需要将新移动和旋转的点反馈回表中

如果是这样,下面的示例显示如何获取点的绝对位置,围绕传入位置居中并旋转:

Imports System.Drawing.Drawing2D

Public Class Form1

    Private mPattern As New List(Of cPattern)

    Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
        ' Small rectangle with rotation around its center:
        Dim pat As New cPattern
        pat.Angle = 45
        pat.Positions.Add(New Point(35, 35))
        pat.Positions.Add(New Point(10, 10))
        pat.Positions.Add(New Point(60, 10))
        pat.Positions.Add(New Point(60, 60))
        pat.Positions.Add(New Point(10, 60))
        mPattern.Add(pat)
    End Sub

    Private Sub picPattern_Paint(sender As Object, e As PaintEventArgs) Handles picPattern.Paint
        Dim G As Graphics = e.Graphics
        Dim center As Point = New Point(picPattern.Width / 2, picPattern.Height / 2)
        For Each pat As cPattern In mPattern
            Dim pts As List(Of Point) = pat.CenterAndRotateAt(center)
            Using cyan As New Pen(Brushes.Cyan, 2)
                For Each pos As Point In pts
                    Dim r As New Rectangle(pos.X, pos.Y, 1, 1)
                    r.Inflate(3, 3)
                    G.DrawEllipse(cyan, r)
                Next
            End Using
        Next
    End Sub

End Class

Public Class cPattern

    Public Angle As Integer
    Public Positions As New List(Of Point)

    Public Function CenterAndRotateAt(ByVal center As Point) As List(Of Point)
        Dim myMatrix As New Matrix
        ' Make the center of rotation for this pattern the new origin:
        myMatrix.Translate(-Me.Positions(0).X, -Me.Positions(0).Y, MatrixOrder.Append)
        ' Rotate the pattern to the desired angle:
        myMatrix.Rotate(Me.Angle, MatrixOrder.Append)
        ' Move the rotated pattern to the desired position:
        myMatrix.Translate(center.X, center.Y, MatrixOrder.Append)

        ' Return the absolute positions of the pattern in the new position with rotation applied:
        ' *** this will NOT change the original points in the pattern! ***
        Dim pts() As Point = Me.Positions.ToArray
        myMatrix.TransformPoints(pts)
        Return New List(Of Point)(pts)
    End Function

End Class

你能展示一张未旋转的图片吗,以及你希望它旋转的图片吗?你想绕什么旋转?…每组点的“质心”?我想你是绕着图片框的中心旋转?感谢你的帮助,我有一系列由桌面定位器设备检索的真实点,我需要显示图像上的点(图像大小小于桌面)。在第二步中,我需要从用户选择的原点旋转这些点,然后我需要检索新点以移动工作台定位器。因此,用户选择一个新原点。我们把重点转移到那里。那么,这些点是否应该按原样旋转角度?或者他们应该以新的原点为中心,并旋转和他们的中心。。。在
cPattern
中的
位置是什么?这是点的数组还是列表?您好,位置是通用的。列表(点F),点应该旋转并居中。旋转中心是列表的第一个点。