/// <summary> /// 设置平移的初态 /// </summary> /// <param name="length">待平移的线的长度</param> /// <param name="distance">待平移的距离</param> public static void SetTranslationStartState(int length, int distance) { TranslationLinelength = length; TranslationDistance = distance; StraitLineAlgo.DrawStraitLineDDA(new pointLoc(0, 0), new pointLoc(0, length)); }
/// <summary> /// 开始平移 /// </summary> public static void BeginTranslation() { for (int i = 0; i < TranslationDistance; i++) { CSys.RefreshCordinateSys(); StraitLineAlgo.DrawStraitLineDDA(new pointLoc(i + 1, 0), new pointLoc(i + 1, TranslationLinelength)); CSys.DrawDots(); } }
/// <summary> /// 顶点画三角形法。此方法画出的三角形边长比需得到的底边略长。 /// </summary> /// <param name="edgeLength">待画的三角形边长</param> /// <param name="Sx">顶点横坐标</param> /// <param name="Sy">顶点横坐标</param> private static void RegularTriangleFixedTopPoint(double edgeLength, double Sx, double Sy) { double length = Math.Round(edgeLength); //得到最接近输入边长的近似边长 double x1, y1, x2, y2; //x1,y1是左侧点的横纵坐标值,x2,y2是右侧点的横纵坐标值。左右是相对于正三角形顶点而言的 x1 = Math.Round(Sx - length / 2); //计算另外两个点的坐标,并将其转换为最接近的整数坐标值 y1 = Math.Round(Sy + Math.Sqrt(3) * length / 2); x2 = Math.Round(Sx + length / 2); y2 = Math.Round(Sy + Math.Sqrt(3) * length / 2); StraitLineAlgo.DrawStraitLineDDA(Sx, Sy, x1, y1);//逆时针方向连接三点 StraitLineAlgo.DrawStraitLineDDA(x1, y1, x2, y2); StraitLineAlgo.DrawStraitLineDDA(x2, y2, Sx, Sy); }
/// <summary> /// 固定底边画三角形法。 /// </summary> /// <param name="edgeLength">待画的三角形边长</param> /// <param name="Sx">底边左端定点横坐标</param> /// <param name="Sy">底边左端定点纵坐标</param> private static void RegularTriangleFixedBottomEdge(double edgeLength, double Sx, double Sy) { double length = Math.Round(edgeLength); //得到最接近输入边长的近似边长 double x0, y0, x2, y2; //x0,y0是顶点的横纵坐标值,x2,y2是右侧顶点的横纵坐标值。左右是相对于正三角形顶点而言的 x0 = Math.Round(Sx + length / 2); //计算另外两个点的坐标,并将其转换为最接近的整数坐标值 y0 = Math.Round(Sy - Math.Sqrt(3) * length / 2); x2 = Math.Round(Sx + length); y2 = Sy; StraitLineAlgo.DrawStraitLineDDA(Sx, Sy, x2, y2);//逆时针方向连接三点 StraitLineAlgo.DrawStraitLineDDA(x2, y2, x0, y0); StraitLineAlgo.DrawStraitLineDDA(x0, y0, Sx, Sy); }
/// <summary> /// 画任意个定点的多边形 /// </summary> /// <param name="pointLoc">存储了多个定点信息的pointLoc型数组</param> public static void CreateGenericPolygon(pointLoc[] pointLocArr) { int polyNum = pointLocArr.Length;//顶点数 //连接各个点 for (int i = 0; i < pointLocArr.Length; i++) { if (i + 1 < pointLocArr.Length) { StraitLineAlgo.DrawStraitLineDDA(pointLocArr[i], pointLocArr[i + 1]); } else { StraitLineAlgo.DrawStraitLineDDA(pointLocArr[i], pointLocArr[0]);//闭合首尾 } } }