public GE_Vector RotateBy(double dRotate) { double dLen = Math.Sqrt(m_X * m_X + m_Y * m_Y); double dAng; if (Geo.fequ(m_X, 0)) { if (m_Y > 0) { dAng = Math.PI / 2; } else if (m_Y < 0) { dAng = Math.PI * 1.5; } else { dAng = 0; } } else { dAng = Math.Atan(m_Y / m_X); } dAng = dAng + dRotate; m_X = dLen * Math.Cos(dAng); m_Y = dLen * Math.Sin(dAng); return(new GE_Vector(m_X, m_Y)); }
//public double GetAngleTo(GE_Vector vector) //{ // double dAng1, dAng2; // if (Geo.fequ(m_X, 0)) { dAng1 = 0; } // else { dAng1 = Math.Atan(m_Y / m_X); } // if (Geo.fequ(vector.X, 0)) { dAng2 = 0; } // else { dAng2 = Math.Atan(vector.Y / vector.X); } // return Geo.Mid_angle(dAng1, dAng2); //} public double GetAngle() { double dAngle = 0; if (Geo.fequ(m_Y, 0)) { if (m_X >= 0) { dAngle = 0; } else { dAngle = Math.PI; } } else { if (Geo.fequ(m_X, 0)) { if (m_Y > 0) { dAngle = Math.PI / 2; } else { dAngle = Math.PI * 1.5; } } else { dAngle = Math.Atan(Math.Abs(m_Y) / Math.Abs(m_X)); if (m_X > 0 && m_Y > 0) { //第一象限 } else if (m_X > 0 && m_Y < 0) { //第四象限 dAngle = Math.PI * 2 - dAngle; } else if (m_X < 0 && m_Y > 0) { //第二象限 dAngle = Math.PI - dAngle; } else { //第三象限 dAngle = Math.PI + dAngle; } } } return(dAngle); }