我有一个位置列表(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
使用此代码,我可以为每个位置画一个圆,但只能在水平模式下。
听起来您需要将新的平移和旋转的点反馈到表中?
如果是这样,那么下面的示例显示获取点的绝对位置,这些点居中并围绕传入的位置旋转:
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
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句