public bool GetAxis(double Alpha, out RPoint pt, out RPoint vec, out double ang) { const double CCF = 1.0; double lR = this.m_R.PT.Dist(); double an = 2 * MyMath.Atan2(lR, this.m_R.R); // if (Math.Abs(an) < 0.1) { vec = pt = RPoint.Zero; ang = 0.0; return(false); //ERR: too small angle for LoadAxis } vec = m_R.PT; vec.Div(lR); // if (Math.Sin(an) * Math.Sin(Alpha * Math.PI / 180.0) < 0.0) { an = -an; vec.Neg(); } pt = this.m_T; double a = vec.SMul(ref pt); // vec.X*pt.X+vec.Y*pt.Y+vec.Z*pt.Z; double [] w = new double[3]; double [] u = new double[3]; w[0] = pt.X - a * vec.X; w[1] = pt.Y - a * vec.Y; w[2] = pt.Z - a * vec.Z; u[0] = w[1] * vec.Z - w[2] * vec.Y; u[1] = w[2] * vec.X - w[0] * vec.Z; u[2] = w[0] * vec.Y - w[1] * vec.X; double b = Math.Tan((Math.PI + an) / 2); int j = 0; if (Math.Abs(vec.X) < Math.Abs(vec.Y)) { j = 1; } double cmp = (j == 0) ? vec.X : vec.Y; if (Math.Abs(cmp) < Math.Abs(vec.Z)) { j = 2; } pt.X = (w[0] + CCF * u[0] * b) / 2; pt.Y = (w[1] + CCF * u[1] * b) / 2; pt.Z = (w[2] + CCF * u[2] * b) / 2; if (j == 0) { b = pt.X / vec.X; } else if (j == 1) { b = pt.Y / vec.Y; } else { b = pt.Z / vec.Z; } pt.X -= b * vec.X; pt.Y -= b * vec.Y; pt.Z -= b * vec.Z; ang = an * 180.0 / Math.PI; return(true); }
public void Div(double v) { PT.Div(v); R /= v; }