I haven't done lines this way in a loooooong time haha, but I'll try to help you. As I understand it, a, b, and c define your line. Then you can calculate x for a given y, and y for a given x.
To calculate a, b, and c, you need two points. You can draw those two points to see the line between them. Create a new form and then override the OnPaint event. Make two points and draw them.
- protected override void OnPaint(PaintEventArgs e)
-
{
-
Graphics g = e.Graphics;
-
-
Point p1 = new Point(50, 75);
-
Point p2 = new Point(300, 125);
-
-
g.DrawLine(Pens.Black, p1, p2);
-
}
Now you can calculate a, b, and c from those points.
- float a = p1.Y - p2.Y;
-
float b = p2.X - p1.X;
-
float c = p1.X * p2.Y - p2.X * p1.Y;
Now we can calculate points... lets say we want to pick an x and calculate y. We need to rearrange our formula...
ax + by = 0
ax + by = -c
by = -c - ax
y = (-c - ax) / b
Keep in mind that b can't be zero when we do it this way. I believe this is the limitation of this method of line drawing. It maps every value of x to a single value for y. So if all your values of Y are at the same x value, there's no way to calculate it.
Anyway, now that we have a, b, and c, we can just pick values for X and calculate Y. Then we can draw them and see where they fit on our original line. This will tell us if we've made a mistake or not.
- if (b != 0)
-
{
-
float newX1 = 75;
-
float newY1 = (-c - a * newX1) / b;
-
-
float newX2 = 275;
-
float newY2 = (-c - a * newX2) / b;
-
-
g.DrawLine(Pens.Red, newX1, newY1, newX2, newY2);
-
}
NOTE: I used this page as a reference...
http://bobobobo.wordpress.com/2008/0...ons-ax-by-c-0/
As you can see, we've done the calculations correctly and the calculated line lays correctly over top of the original line.
Since you didn't post any of your values, you'll need to do this same investigation on your own (which is good for you to do anyway, to be honest). See if your calculated line lays correctly over top of your original line. If it doesn't, check your math! This is actually what I had to do in generating this... the first couple of tries I found I wasn't getting the correct result, and it turned out I made a few math errors ;) Give it a try and if you're still having trouble, please post with more information so we can see what values you're using.