private static MyPoint mpBaseVector = new MyPoint(1.0f, 0);//使用x轴做基向量 /// <summary> /// 按照参数2指定的向量与基向量的夹角计算参数1对应的绝对元胞坐标 /// </summary> /// <param name="vector"></param> /// <returns></returns> internal static Point GetRealXY(Point point, MyPoint newVector) { if (newVector == null) { ThrowHelper.ThrowArgumentNullException("输入的参数不能为零"); } //获取正弦和余弦值并且进行旋转变换 SinCos sc = VectorTools.getSinCos(mpBaseVector, newVector); return(Coordinates.Rotate(point, sc)); }
/// <summary> /// 判定角度并且输出角度的正弦和余弦值,315-45 为0度 45-135度变为90度 /// 135-225 为180度 225-315度变为270度, /// </summary> internal static SinCos getSinCos(MyPoint mpBaseVector, MyPoint mpVector) { //由于0.707小于根号2的一半所以45度变为90度 double dCosineValue = VectorTools.getCosine(mpBaseVector, mpVector); //-45 180 +45度的左开右闭闭区间 if (-1.001 <= dCosineValue && dCosineValue < -0.708) //-根号2的是是1.414 其一半 是0.707 { return(new SinCos(0, -1)); //cosine 180 是-1; } int irtlPos = VectorTools.getVectorPos(mpBaseVector, mpVector); if (-0.708 <= dCosineValue && dCosineValue < 0.708) { ///判断y位于基向量的上方还是下方 if (irtlPos < 0) //-45 270 +45度 { return(new SinCos(-1, 0)); //270 } if (irtlPos > 0) // -45 90 +45度 { return(new SinCos(1, 0)); //90 } else//iPos==0 当前角度下 这是不可能出现的 { throw new Exception("不可能出现的值"); } } ///这之间的有可能是零度,有可能是360度 if (0.708 <= dCosineValue && dCosineValue <= 1.001) { //315度到44度之间全部当作0度处理 return(new SinCos(0, 1)); } throw new Exception("不可能没有捕获所有的角度值"); }