public Vector2_DW Rotate(Vector2_DW ptBase, double angleDegree) { Vector2_DW ptRet = new Vector2_DW(); Vector2_DW vec = this - ptBase; double angleRadium = ToolsMath_DW.Angle2Radium(angleDegree); double xOffset = (vec.X * Math.Cos(angleRadium) - vec.Y * Math.Sin(angleRadium)); double yOffset = (vec.X * Math.Sin(angleRadium) + vec.Y * Math.Cos(angleRadium)); ptRet = ptBase + new Vector2_DW(xOffset, yOffset); return(ptRet); }
//返回两向量的夹角(角度制) static public double Angle(Vector3_DW lhs, Vector3_DW rhs) { double ll = lhs.Magnitude(); double rl = rhs.Magnitude(); if (ToolsMath_DW.IsZero(ll) || ToolsMath_DW.IsZero(rl)) { return(0); } double angle = Math.Acos((lhs.X * rhs.X + lhs.Y * rhs.Y + lhs.Z * rhs.Z) / (ll * rl)); angle *= (180 / Math.PI); return(angle); }
public Vector2_DW Mirror(Vector2_DW lineSt, Vector2_DW lineEnd) { Vector2_DW ptRet = new Vector2_DW(); Vector2_DW vecPer = (lineSt - lineEnd); Vector2_DW vec = new Vector2_DW(-vecPer.Y, vecPer.X); Vector2_DW ptTmp = new Vector2_DW(this + vec); Vector2_DW ptIntersect = new Vector2_DW(); if (ToolsMath_DW.LineXLine(this, ptTmp, lineSt, lineEnd, ref ptIntersect) != LineIntersectType.None) { ptRet = ptIntersect + ptIntersect - this; } return(ptRet); }
/// <summary> /// 判断直线段与矩形是否相交(注:当线段全部在矩形内,也认为相交) /// 1,线段端点是否在矩形内,在,true /// 2,线段包围框是否和矩形相交,否,false /// 3,矩形四个顶点是否在线段两侧,在true,不在,false /// </summary> /// <param name="lStScreen"></param> /// <param name="lEndScreen"></param> /// <param name="bx"></param> /// <returns></returns> public static bool LineSegmenXBox(Vector2_DW lStScreen, Vector2_DW lEndScreen, Box2D bx) { if (ToolsMath_DW.PtInBox(bx, lStScreen) && ToolsMath_DW.PtInBox(bx, lEndScreen)) { return(true); } Box2D bxLine = ToolsMath_DW.GetLineMinBox(lStScreen, lEndScreen); if (!ToolsMath_DW.BoxXBox(bx, bxLine)) { return(false); } Vector2_DW vecLn = lStScreen - lEndScreen; Vector2_DW vBxLeftUpper = bx._min - lEndScreen; Vector2_DW vBxRightTop = (new Vector2_DW(bx._max.X, bx._min.Y)) - lEndScreen; Vector2_DW vBxRightBtm = bx._max - lEndScreen; Vector2_DW vBxLeftBtm = (new Vector2_DW(bx._min.X, bx._max.Y)) - lEndScreen; double f1 = Vector2_DW.Cross(vecLn, vBxLeftUpper); double f2 = Vector2_DW.Cross(vecLn, vBxRightTop); double f3 = Vector2_DW.Cross(vecLn, vBxRightBtm); double f4 = Vector2_DW.Cross(vecLn, vBxLeftBtm); if ((f1 >= 0 && f2 >= 0 && f3 >= 0 && f4 >= 0) || (f1 <= 0 && f2 <= 0 && f3 <= 0 && f4 <= 0)) { return(false); } else { return(true); } }
//返回两个向量之间的夹角(角度制)(0-180) static public double Angle(Vector2_DW from, Vector2_DW to) { return(Math.Acos(ToolsMath_DW.Clamp(Vector2_DW.Dot(from.Normalize(), to.Normalize()), -1f, 1f)) * 57.29578f); }