private double ComputeDerivative(int deriv, double ha, double hb, double hc) { var perturb = 0.2; // perturbation amount in mm or degrees var hiParams = new Delta(this.diagonal, this.radius, this.homedHeight, this.xstop, this.ystop, this.zstop, this.xadj, this.yadj, this.zadj); var loParams = new Delta(this.diagonal, this.radius, this.homedHeight, this.xstop, this.ystop, this.zstop, this.xadj, this.yadj, this.zadj); switch (deriv) { case 0: case 1: case 2: break; case 3: hiParams.radius += perturb; loParams.radius -= perturb; break; case 4: hiParams.xadj += perturb; loParams.xadj -= perturb; break; case 5: hiParams.yadj += perturb; loParams.yadj -= perturb; break; case 6: hiParams.diagonal += perturb; loParams.diagonal -= perturb; break; } hiParams.Recalc(); loParams.Recalc(); var zHi = hiParams.InverseTransform((deriv == 0) ? ha + perturb : ha, (deriv == 1) ? hb + perturb : hb, (deriv == 2) ? hc + perturb : hc); var zLo = loParams.InverseTransform((deriv == 0) ? ha - perturb : ha, (deriv == 1) ? hb - perturb : hb, (deriv == 2) ? hc - perturb : hc); return((zHi - zLo) / (2 * perturb)); }
private double ComputeDerivative(int deriv, double ha, double hb, double hc) { var perturb = 0.2; // perturbation amount in mm or degrees var hiParams = new Delta(this.diagonal, this.radius, this.homedHeight, this.xstop, this.ystop, this.zstop, this.xadj, this.yadj, this.zadj); var loParams = new Delta(this.diagonal, this.radius, this.homedHeight, this.xstop, this.ystop, this.zstop, this.xadj, this.yadj, this.zadj); switch (deriv) { case 0: case 1: case 2: break; case 3: hiParams.radius += perturb; loParams.radius -= perturb; break; case 4: hiParams.xadj += perturb; loParams.xadj -= perturb; break; case 5: hiParams.yadj += perturb; loParams.yadj -= perturb; break; case 6: hiParams.diagonal += perturb; loParams.diagonal -= perturb; break; } hiParams.Recalc(); loParams.Recalc(); var zHi = hiParams.InverseTransform((deriv == 0) ? ha + perturb : ha, (deriv == 1) ? hb + perturb : hb, (deriv == 2) ? hc + perturb : hc); var zLo = loParams.InverseTransform((deriv == 0) ? ha - perturb : ha, (deriv == 1) ? hb - perturb : hb, (deriv == 2) ? hc - perturb : hc); return (zHi - zLo) / (2 * perturb); }