Hallo Hannes
Hier wird die Kuvenlänge linear aufgeteilt.
Die Zahl der Abschnitte ist einstellbar.
Die Punktwerte sind in % der Kurvenhöhe angegeben.
Für die Berechnung braucht die Bezierkurve nicht auf dem Bildschirm angezeigt werden.
Die Berechnung wird über die Pixel im GraphicsPath gemacht.
Imports System.Drawing.Drawing2D
Public Class Form1
Dim bzp() As Point = {New Point(50, 450), New Point(100, 400), New Point( _
400, 100), New Point(450, 50)}
Dim gp, gpath As New GraphicsPath
Dim plist As New List(Of RectangleF)
Dim ts As Int32 = 10 ' Anzahl der Abschnitte
Dim curpoint As Int32
Dim ptsvisible As Boolean
Private Sub Form1_MouseDown(ByVal sender As Object, ByVal e As _
System.Windows.Forms.MouseEventArgs) Handles Me.MouseDown
curpoint = -1
If ptsvisible AndAlso gpath.IsVisible(e.Location) Then
For i As Int32 = 1 To 2
If Math.Abs(e.X - bzp(i).X) < 6 AndAlso Math.Abs(e.Y - bzp( _
i).Y) < 6 Then
curpoint = i
End If
Next
End If
If e.Button = Windows.Forms.MouseButtons.Right Then
ptsvisible = Not ptsvisible
If Not ptsvisible Then
GetPoints()
End If
Me.Refresh()
End If
End Sub
Private Sub Form1_Paint(ByVal sender As Object, ByVal e As _
System.Windows.Forms.PaintEventArgs) Handles MyBase.Paint
e.Graphics.SmoothingMode = SmoothingMode.HighQuality
e.Graphics.DrawRectangle(Pens.DimGray, 50, 50, 400, 400)
e.Graphics.DrawBezier(New Pen(Color.Yellow, 2), bzp(0), bzp(1), bzp(2), _
bzp(3))
If ptsvisible Then
gpath.Reset()
For i As Int32 = 0 To 3
gpath.AddEllipse(bzp(i).X - 5, bzp(i).Y - 5, 10, 10)
Next
e.Graphics.FillPath(Brushes.Red, gpath)
Else
Dim max As Int32 = plist(plist.Count - 1).Width
Dim ppos As Int32 = 50
For i As Int32 = 1 To ts - 1
For Each r As RectangleF In plist
If r.Width >= i * max \ ts Then
e.Graphics.FillEllipse(Brushes.Red, r.X - 5, r.Y - 5, _
10, 10)
e.Graphics.DrawString((r.Height / 10).ToString(Format( _
"f2")) & " %", Me.Font, Brushes.Yellow, 2, ppos)
ppos += 15
Exit For
End If
Next
Next
End If
End Sub
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As _
System.EventArgs) Handles MyBase.Load
Me.SetStyle(ControlStyles.DoubleBuffer Or ControlStyles.UserPaint Or _
ControlStyles.AllPaintingInWmPaint, True)
Me.SetBounds(100, 100, 510, 520)
Me.BackColor = Color.Black
Me.Text = "Bezierkurve mit linearer Aufteilung der Länge"
GetPoints()
End Sub
Private Sub Form1_MouseMove(ByVal sender As Object, ByVal e As _
System.Windows.Forms.MouseEventArgs) Handles Me.MouseMove
If ptsvisible AndAlso curpoint > -1 AndAlso e.Button = _
Windows.Forms.MouseButtons.Left Then
If e.X >= 50 AndAlso e.X <= 450 AndAlso e.Y >= 50 AndAlso e.Y _
<= 450 Then
bzp(curpoint) = New Point(e.X, e.Y)
Me.Refresh()
End If
End If
End Sub
Sub GetPoints()
Dim r As RectangleF
r.Location = bzp(0)
plist.Clear()
gp.Reset()
gp.AddBezier(bzp(0), bzp(1), bzp(2), bzp(3))
Do
plist.Add(r)
Select Case True
Case gp.IsOutlineVisible(r.X + 1, r.Y - 1, Pens.Black)
r.X += 1
r.Y -= 1
r.Width += 1414
Case gp.IsOutlineVisible(r.X, r.Y - 1, Pens.Black)
r.Y -= 1
r.Width += 1000
Case gp.IsOutlineVisible(r.X + 1, r.Y, Pens.Black)
r.X += 1
r.Width += 1000
Case gp.IsOutlineVisible(r.X + 1, r.Y + 1, Pens.Black)
r.X += 1
r.Y -= 1
r.Width += 1414
Case Else
Exit Do
End Select
r.Height = (400 - (r.Y - 50)) / 0.4
Loop
End Sub MfG GPM |