|
Hey guys, I have pretty much figured out my regression line doing some calculations, but drawing it is where I am stuck. The line comes from the y axis and goes through the middle of the chart roughly, once I get these two points I draw the line, but I do not know how to draw a line THROUGH the middle point to the end of the chart, can anyone please help me out?
Here is my chart code:
chart1.Series["Regression Line"].Points.AddXY(0, b0);
chart1.Series["Regression Line"].Points.AddXY(xAverage, yAverage);
chart1.Series["Regression Line"].ChartType = SeriesChartType.Line;
chart1.Series["Regression Line"].Color = Color.Red;
You can see the line goes from one point to another, but its only half the line, any assistance would be greatly appreciated I am completely stumped!
Many thanks!!!
|
|
|
|
|
The maths is pretty simple. If you have a line from (x0, y0) to (x1, y1) and want to extend it as far again to (x2, y2), then (x1, y1) is the midpoint of the line. x1 = (x0 + x2) / 2, etc.
Massage it a bit and you get
x2 = 2 * x1 - x0, y2 = 2 * y1 - y0.
Refactor to your variable names and that's it
Cheers,
Peter
Software rusts. Simon Stephenson, ca 1994. So does this signature. me, 2012
|
|
|
|
|
Thanks very much Peter I shall try and figure this out right now! Appreciated!
|
|
|
|
|
Peter after some experimenting, I got there, thanks to you, your equation made sense and it worked! Much appreciated!
Thank you!!
|
|
|
|
|
You're welcome.
Peter
Software rusts. Simon Stephenson, ca 1994. So does this signature. me, 2012
|
|
|
|