Ok... I have a graphics path ... and I want it to be symmetrical ... so I thought I would just draw the right 1/2 with positive X values... then use 0-x on the points x values to flip it by cloning and reversing the PathData ...
but I can't seem to be able to append to point data??
I was doing it like this:
vb Code:
gpPerson.PathData.Points = gpPerson.PathData.Points.ToArray.Concat(gpPerson.PathData.Points.ToArray.Select(Function(x) New PointF(-x.X, x.Y)).Reverse).ToArray
Flip and translate the path by whatever means you see fit. Then add it back to the original path with AddPath. Here's an example that does use a matrix for flip and translate:
Code:
Private Function ReflectPath(gp As Drawing2D.GraphicsPath) As Drawing2D.GraphicsPath
Using mirror As New Drawing2D.GraphicsPath(gp.PathPoints, gp.PathTypes)
Dim mtx As New Drawing2D.Matrix(-1, 0, 0, 1, gp.GetBounds.Width * 2.1F, 0) 'flip and translate X
mirror.Transform(mtx)
gp.AddPath(mirror, False)
End Using
Return gp
End Function
Thanks... Almost there, but... I need the paths to be connected ... and the problem with this is shown below (I expanded the gap in between the mirror a little so that you can see what is going on)... this is why I reversed it in my example ...
To prevent the cross-line, reverse the direction of the reflected part with GraphicsPath.Reverse. Add CloseFigure to complete the joins. See the improved version of the ReflectPath function in this little ready-to-run example. Scribble with the left mouse button to see the effect.
Code:
Public Class Form1
Private startDraw As Point
Private pth, dblPath As Drawing2D.GraphicsPath
Private Sub Form1_MouseDown(sender As Object, e As System.Windows.Forms.MouseEventArgs) Handles Me.MouseDown
If e.Button = Windows.Forms.MouseButtons.Left Then
pth = New Drawing2D.GraphicsPath
dblPath = New Drawing2D.GraphicsPath
startDraw = e.Location
End If
End Sub
Private Sub Form1_MouseMove(sender As Object, e As System.Windows.Forms.MouseEventArgs) Handles Me.MouseMove
If e.Button = Windows.Forms.MouseButtons.Left Then
pth.AddLine(startDraw, e.Location)
startDraw = e.Location
Me.Invalidate()
End If
End Sub
Private Sub Form1_MouseUp(sender As Object, e As System.Windows.Forms.MouseEventArgs) Handles Me.MouseUp
dblPath = ReflectPath(pth)
Me.Invalidate()
End Sub
Private Sub Form1_Paint(sender As Object, e As System.Windows.Forms.PaintEventArgs) Handles Me.Paint
If dblPath IsNot Nothing Then
Using pn As New Pen(Color.Red, 2)
e.Graphics.DrawPath(pn, dblPath)
End Using
End If
If pth IsNot Nothing Then
Using pn As New Pen(Color.Gray, 2)
e.Graphics.DrawPath(pn, pth)
End Using
End If
End Sub
Private Function ReflectPath(gp As Drawing2D.GraphicsPath) As Drawing2D.GraphicsPath
Dim Xtranslation As Single = 2 * gp.GetBounds.Right
Dim mtx As New Drawing2D.Matrix(-1, 0, 0, 1, Xtranslation, 0)
Dim pth As New Drawing2D.GraphicsPath(gp.PathPoints, gp.PathTypes)
Using mirror As New Drawing2D.GraphicsPath(gp.PathPoints, gp.PathTypes)
mirror.Transform(mtx)
mirror.Reverse()
pth.AddPath(mirror, True)
pth.CloseFigure()
End Using
Return pth
End Function
End Class
You may need to play around with the XTranslation value to get the two halves to line up nicely. 2*GetBounds.Right worked out in the above example but I am not sure if it will apply in your code.
Isn't checking for left mouse in the Mouse Up event so, ......
drag with the left mouse, and tap the right mouse periodically while continuing to drag with the left, for interesting side effect.
Wasn't trying to draw anything, just a few back and forth up the form with periodic right clicks, and release, and it looks rather bunny like to me.