Stroke.SelfIntersections 속성
업데이트: 2007년 11월
Stroke 개체의 자체 교차 지점을 가져옵니다.
네임스페이스: Microsoft.Ink
어셈블리: Microsoft.Ink(Microsoft.Ink.dll)
구문
‘선언
Public ReadOnly Property SelfIntersections As Single()
‘사용 방법
Dim instance As Stroke
Dim value As Single()
value = instance.SelfIntersections
public float[] SelfIntersections { get; }
public:
property array<float>^ SelfIntersections {
array<float>^ get ();
}
/** @property */
public float[] get_SelfIntersections()
public function get SelfIntersections () : float[]
속성 값
형식: array<System.Single[]
Stroke 개체의 자체 교차 지점을 나타내는 부동 소수점 인덱스 값의 배열입니다.
설명
자체 교차 지점은 스트로크 자체에서 교차하는 스트로크의 점입니다.
부동 소수점 인덱스는 스트로크의 두 점 사이에 있는 위치를 나타내는 부동 소수점 값입니다. 예를 들어 스트로크에서 첫 번째 점이 0.0이고 두 번째 점이 1.0인 경우 0.5는 첫 번째 점과 두 번째 점 사이의 중간 지점입니다. 마찬가지로 부동 소수점 인덱스 값 37.25는 스트로크의 37번과 38번 점 사이의 선에서 25% 위치를 나타냅니다.
참고
부동 소수점 인덱스는 각 교차 및 선 세그먼트 조합에 대해 반환됩니다. 스트로크의 교차 지점이 하나인 경우 SelfIntersections 속성에서는 교차 지점의 일부인 선 세그먼트마다 하나씩 두 개의 자체 교차 지점을 반환하게 됩니다.
예제
이 C# 예제에서는 각 Stroke 개체에 기록되는 몇 가지 정보를 보여 줍니다. 호출하는 프로그램에서는 메뉴 항목을 사용하여 각 스트로크의 점, 다중선 첨점, 베지어 점, 베지어 첨점 및 자체 교차 지점의 표시 여부를 전환합니다. Renderer 개체의 InkSpaceToPixel 메서드는 화면 표시를 위해 점을 변환하는 데 사용됩니다. LocatePoint 메서드는 자체 교차 위치를 보간하는 데 사용됩니다.
Microsoft.Ink.InkCollector theInkCollector;
// Event handler for the form's load event.
private void Form1_Load(object sender, System.EventArgs e)
{
// Create the InkCollector.
theInkCollector = new InkCollector(this.Handle);
// Attach an event handler for the Stroke event.
theInkCollector.Stroke += new InkCollectorStrokeEventHandler(theInkCollector_Stroke);
// Enable the InkCollector.
theInkCollector.Enabled = true;
}
// Event handler for the InkCollector's Stroke event.
private void theInkCollector_Stroke(object sender, InkCollectorStrokeEventArgs e)
{
// Force the form to repaint.
Refresh();
}
// Event handler for the Clear menu's Click event.
private void menuClear_Click(object sender, System.EventArgs e)
{
// Delete the strokes in the InkCollector.
theInkCollector.Ink.DeleteStrokes();
// Force the form to repaint.
Refresh();
}
private void menuExit_Click(object sender, System.EventArgs e)
{
this.Close();
}
// Event handler for the Click event for subitems of the Display menu.
private void menuDisplayItem_Click(object sender, System.EventArgs e)
{
// Check each subitem to see if it was clicked.
foreach (System.Windows.Forms.MenuItem menu in menuDisplay.MenuItems)
{
if (sender == menu)
{
// Toggle the menu item's checked property.
menu.Checked = !menu.Checked;
}
}
// Force the form to repaint.
this.Refresh();
}
// Event handler for the form's Paint event.
private void Form1_Paint(object sender, System.Windows.Forms.PaintEventArgs e)
{
Graphics g = e.Graphics;
// Highlight specific points or cusps of each stroke.
Strokes theStrokes = theInkCollector.Ink.Strokes;
foreach (Stroke theStroke in theStrokes)
{
// Convert the stroke's points and Bezier points from ink space to pixel coordinates.
Point [] ptBezierPoints = theStroke.BezierPoints;
Point [] ptStrokePoints = theStroke.GetPoints();
theInkCollector.Renderer.InkSpaceToPixel(g, ref ptBezierPoints);
theInkCollector.Renderer.InkSpaceToPixel(g, ref ptStrokePoints);
// If all points is checked, highlight the points of the stroke.
if (menuAllPoints.Checked)
{
foreach (Point pt in ptStrokePoints)
{
// draw a little diagonal line from each point
g.DrawEllipse(Pens.Magenta, pt.X-2, pt.Y-2, 4, 4);
}
}
// If polyline cusps is checked, highlight the cusps of the stroke.
if (menuPolylineCusps.Checked)
{
int[] theCusps = theStroke.PolylineCusps;
foreach (int i in theCusps)
{
// Draw a little rectangle around each polyline cusp.
g.DrawEllipse(Pens.BlueViolet, ptStrokePoints[i].X - 3, ptStrokePoints[i].Y - 3, 6, 6);
}
}
// If Bezier points is checked, highlight the Bezier points of the stroke.
if (menuBezierPoints.Checked)
{
foreach (Point pt in ptBezierPoints)
{
// Draw a little diagonal line from each Bezier point.
g.DrawEllipse(Pens.Goldenrod, pt.X-4, pt.Y-4, 8, 8);
}
}
// If Bezier cusps is checked, highlight the Bezier cusps of the stroke.
if (menuBezierCusps.Checked)
{
int [] theCusps = theStroke.BezierCusps;
foreach (int i in theCusps)
{
// Draw a little rectangle around each Bezier cusp.
g.DrawEllipse(Pens.Blue,
ptBezierPoints[i].X-5, ptBezierPoints[i].Y-5, 10, 10);
}
}
// If self intersections is checked, highlight the self intersections of the stroke.
if (menuSelfIntersections.Checked)
{
float [] theSelfIntersectionLocationsArray = theStroke.SelfIntersections;
foreach (float f in theSelfIntersectionLocationsArray)
{
Point pt = LocatePoint(theStroke, f);
theInkCollector.Renderer.InkSpaceToPixel(g, ref pt);
// Draw a little circle around each intersection.
g.DrawEllipse(Pens.Red, pt.X-7, pt.Y-7, 14, 14);
}
}
}
}
// This function returns the approximate point along
// a stroke represented by a float, as a Point.
private Point LocatePoint(Stroke theStroke, float theFIndex)
{
// Get the two nearest points to the point of interest.
Point [] ptStrokePoints = theStroke.GetPoints((int)Math.Floor(theFIndex), 2);
// Get fractional part to interpolate the distance between the points.
float theFraction = theFIndex - (float)Math.Floor(theFIndex);
int deltaX = (int)((ptStrokePoints[1].X - ptStrokePoints[0].X) * theFraction);
int deltaY = (int)((ptStrokePoints[1].Y - ptStrokePoints[0].Y) * theFraction);
// Return the interpolated point.
return new Point(ptStrokePoints[0].X + deltaX, ptStrokePoints[0].Y + deltaY);
}
이 Microsoft Visual Basic .NET 예제에서는 각 Stroke 개체에 기록되는 몇 가지 정보를 보여 줍니다. 호출하는 프로그램에서는 메뉴 항목을 사용하여 각 스트로크의 점, 다중선 첨점, 베지어 점, 베지어 첨점 및 자체 교차 지점의 표시 여부를 전환합니다. Renderer 개체의 InkSpaceToPixel 메서드는 화면 표시를 위해 점을 변환하는 데 사용됩니다. LocatePoint 메서드는 자체 교차 위치를 보간하는 데 사용됩니다.
Dim WithEvents theInkCollector As Microsoft.Ink.InkCollector
' Event handler for the form's Load event.
Private Sub Form1_Load(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles MyBase.Load
' Create and enable the InkCollector
theInkCollector = New Microsoft.Ink.InkCollector(Me.Handle)
theInkCollector.Enabled = True
' Associate the Click event handler with subitems of the Display menu.
AddHandler menuAllPoints.Click, AddressOf menuDisplayItem_Click
AddHandler menuPolylineCusps.Click, AddressOf menuDisplayItem_Click
AddHandler menuBezierPoints.Click, AddressOf menuDisplayItem_Click
AddHandler menuBezierCusps.Click, AddressOf menuDisplayItem_Click
AddHandler menuSelfIntersections.Click, AddressOf menuDisplayItem_Click
End Sub
' Event handler for the InkCollector's Stroke event.
Private Sub theInkCollector_Stroke(ByVal sender As Object, _
ByVal e As Microsoft.Ink.InkCollectorStrokeEventArgs) Handles theInkCollector.Stroke
' Force the form to repaint.
Me.Refresh()
End Sub
' Event handler for the Clear menu's Click event.
Private Sub menuClear_Click(ByVal sender As Object, _
ByVal e As System.EventArgs) Handles menuClear.Click
' Delete the strokes in the InkCollector.
theInkCollector.Ink.DeleteStrokes()
' Force the form to repaint.
Me.Refresh()
End Sub
' Event handler for the Click event for subitems of the Display menu.
Private Sub menuDisplayItem_Click(ByVal sender As Object, _
ByVal e As System.EventArgs)
' Check each subitem to see if it was clicked.
For Each menu As System.Windows.Forms.MenuItem In menuDisplay.MenuItems
If (sender Is menu) Then
' Toggle the menu item's checked property.
menu.Checked = Not menu.Checked
End If
Next
' Force the form to repaint.
Me.Refresh()
End Sub
' Event handler for the form's Paint event.
Private Sub Form1_Paint(ByVal sender As Object, _
ByVal e As System.Windows.Forms.PaintEventArgs) Handles MyBase.Paint
Dim g As Graphics = e.Graphics
' Highlight specific points or cusps of each stroke.
Dim theStrokes As Microsoft.Ink.Strokes = theInkCollector.Ink.Strokes
For Each theStroke As Microsoft.Ink.Stroke In theStrokes
' Convert the stroke's points and Bezier points from ink space to pixel coordinates.
Dim ptBezierPoints() As Point = theStroke.BezierPoints
Dim ptStrokePoints() As Point = theStroke.GetPoints()
theInkCollector.Renderer.InkSpaceToPixel(g, ptBezierPoints)
theInkCollector.Renderer.InkSpaceToPixel(g, ptStrokePoints)
' If all points is checked, highlight the points of the stroke.
If (menuAllPoints.Checked) Then
For Each pt As Point In ptStrokePoints
' draw a little diagonal line from each point
g.DrawEllipse(Pens.Magenta, pt.X - 2, pt.Y - 2, 4, 4)
Next
End If
' If polyline cusps is checked, highlight the cusps of the stroke.
If (menuPolylineCusps.Checked) Then
Dim theCusps() As Integer = theStroke.PolylineCusps
For Each i As Integer In theCusps
' Draw a little rectangle around each polyline cusp.
g.DrawEllipse(Pens.BlueViolet, ptStrokePoints(i).X - 3, ptStrokePoints(i).Y - 3, 6, 6)
Next
End If
' If Bezier points is checked, highlight the Bezier points of the stroke.
If (menuBezierPoints.Checked) Then
For Each pt As Point In ptBezierPoints
' Draw a little diagonal line from each Bezier point.
g.DrawEllipse(Pens.Goldenrod, pt.X - 4, pt.Y - 4, 8, 8)
Next
End If
' If Bezier cusps is checked, highlight the Bezier cusps of the stroke.
If (menuBezierCusps.Checked) Then
Dim theCusps() As Integer = theStroke.BezierCusps
For Each i As Integer In theCusps
' Draw a little rectangle around each Bezier cusp.
g.DrawEllipse(Pens.Blue, ptBezierPoints(i).X - 5, ptBezierPoints(i).Y - 5, 10, 10)
Next
End If
' If self intersections is checked, highlight the self intersections of the stroke.
If (menuSelfIntersections.Checked) Then
Dim theSelfIntersectionLocationsArray() As Single = theStroke.SelfIntersections
For Each f As Single In theSelfIntersectionLocationsArray
Dim pt As Point = LocatePoint(theStroke, f)
theInkCollector.Renderer.InkSpaceToPixel(g, pt)
' Draw a little circle around each intersection.
g.DrawEllipse(Pens.Red, pt.X - 7, pt.Y - 7, 14, 14)
Next
End If
Next
End Sub
' This function returns the approximate point along
' a stroke represented by a float, as a Point.
Private Function LocatePoint(ByVal theStroke As Microsoft.Ink.Stroke, _
ByVal theFIndex As Single) As Point
' Get the two nearest points to the point of interest.
Dim ptStrokePoints() As Point = theStroke.GetPoints(Math.Floor(theFIndex), 2)
' Get fractional part to interpolate the distance between the points.
Dim theFraction As Single = theFIndex - Math.Floor(theFIndex)
Dim deltaX As Integer = (ptStrokePoints(1).X - ptStrokePoints(0).X) * theFraction
Dim deltaY As Integer = (ptStrokePoints(1).Y - ptStrokePoints(0).Y) * theFraction
' Return the interpolated point.
LocatePoint = New Point(ptStrokePoints(0).X + deltaX, ptStrokePoints(0).Y + deltaY)
End Function
플랫폼
Windows Vista
.NET Framework 및 .NET Compact Framework에서 모든 플랫폼의 전체 버전을 지원하지는 않습니다. 지원되는 버전의 목록을 보려면 .NET Framework 시스템 요구 사항을 참조하십시오.
버전 정보
.NET Framework
3.0에서 지원