Ich habe 1 Zeile mit 2 bekannten Punkten:iterieren N Punkte, die auf eine andere Linie, die senkrecht sind
PointF p2_1 = new PointF();
p2_1.X = 100; // x1
p2_1.Y = 150; // y1
PointF p2_2 = new PointF();
p2_2.X = 800; // x2
p2_2.Y = 500; // y2
float dx = p2_2.X - p2_1.X;
float dy = p2_2.Y- p2_1.Y;
float slope = dy/dx; // slope m
float intercept = p2_1.Y - slope * p2_1.X; // intercept c
// y = mx + c
Ich möchte bis 10 Pixel nach links (oder rechts), um 1 Zeile iterieren (at x1, y1).
Die roten Punkte sind diejenigen, die ich Prozess möchten. Beispiel:
for (int i = 10; i > 0; i--)
{
// start with distant coordinates
PointF new_point = new Point(); // (grab x,y, coords accordingly)
// repeat until I'm at (x1, y1)
}
Wie durchläufe ich diese Coords?
Ich wollte nur diese hier werfen: [Eine Implementierung von Bresenhamschen Strichzeichnung Algorithmus] (http://ericw.ca/notes/bresenhams-line-algorithm-in-csharp.html). Es ist ziemlich kurz und gibt Ihnen ein handliches 'IEnumerable', mit dem zu iterieren ist. Sie können es mit den End-Coords aus den Antworten unten füttern. –