Apologies for the poor question. I have had more negative feedback for this than positive feedback for questions where I put several nicely drawn images!
So, here it is...
Edit:
I have a formula to work out the coefficients of a quadratic when given 3 plots on the line.
quadraticCoefficient = (((p2.y - p1.y) x (p1.x - p3.x)) + ((p3.y - p1.y) x (p2.x - p1.x))) / ((p1.x - p3.x) x ((p2.x x p2.x) - (p1.x x p1.x)) + ((p2.x - p1.x) x ((p3.x x p3.x) - (p1.x x p1.x)))); linearCoefficient = ((p2.y - p1.y) - quadraticCoefficient x ((p2.x x p2.x) - (p1.x x p1.x))) / (p2.x - p1.x); fixedTerm = p1.y - (quadraticCoefficient x p1.x x p1.x) - (linearCoefficient x p1.x);
Where p1, p2 and p3 are all plots along the line.
I am interested in a similar formula that would allow me to work out each coefficient of a cubic for 4 given points.
Original:
Here is some c++ I have to find the coefficients of a quadratic.
RS_EquationQ getEquationQ(const RS_PlotF p1, const RS_PlotF p2, const RS_PlotF p3) { RS_EquationQ e; e.quadraticCoefficient = (((p2.y - p1.y) * (p1.x - p3.x)) + ((p3.y - p1.y) * (p2.x - p1.x))) / ((p1.x - p3.x) * ((p2.x * p2.x) - (p1.x * p1.x)) + ((p2.x - p1.x) * ((p3.x * p3.x) - (p1.x * p1.x)))); e.linearCoefficient = ((p2.y - p1.y) - e.quadraticCoefficient * ((p2.x * p2.x) - (p1.x * p1.x))) / (p2.x - p1.x); e.fixedTerm = p1.y - (e.quadraticCoefficient * p1.x * p1.x) - (e.linearCoefficient * p1.x); return e; }
I would like to write an equivilent function for a cubic. If anyone could point me in the direction of a formula (or appropriate reading material) ...I would appreciate it!