protected override void OnDraw(Canvas canvas) { int cxCompass = MeasuredWidth / 2; int cyCompass = MeasuredHeight / 2; float radiusCompass; if (cxCompass > cyCompass) { radiusCompass = (float)(cyCompass * 0.9); } else { radiusCompass = (float)(cxCompass * 0.9); } canvas.DrawCircle(cxCompass, cyCompass, radiusCompass, paint); canvas.DrawLine(cxCompass - 10, cyCompass, cxCompass + 10, cyCompass, paint); canvas.DrawLine(cxCompass, cyCompass - 10, cxCompass, cyCompass + 10, paint); canvas.DrawRect(0, 0, MeasuredWidth, MeasuredHeight, paint); canvas.DrawText("N", cxCompass, cyCompass - radiusCompass - 10, paint); canvas.DrawText("S", cxCompass, cyCompass + radiusCompass + 30, paint); canvas.DrawText("E", cxCompass + radiusCompass + 5, cyCompass, paint); canvas.DrawText("W", cxCompass - radiusCompass - 30, cyCompass, paint); if (!firstDraw) { TdPoint P1 = new TdPoint(); TdPoint P2 = new TdPoint(); TdPoint P0 = new TdPoint(); TdPoint Ps = new TdPoint(); P0.X = (cxCompass + radiusCompass * Math.Sin((double)(direction - 180 * Values.tyfs) * 3.14 / 180) * (float)(dip / 90)); P0.Y = (cyCompass - radiusCompass * Math.Cos((double)(direction - 180 * Values.tyfs) * 3.14 / 180) * (float)(dip / 90)); P1.X = (cxCompass + radiusCompass * Math.Sin((double)(direction + 90) * 3.14 / 180)); P1.Y = (cyCompass - radiusCompass * Math.Cos((double)(direction + 90) * 3.14 / 180)); P2.X = (cxCompass + radiusCompass * Math.Sin((double)(direction - 90) * 3.14 / 180)); P2.Y = (cyCompass - radiusCompass * Math.Cos((double)(direction - 90) * 3.14 / 180)); Ps.X = (cxCompass + radiusCompass * Math.Sin((double)(Lim360(direction + 180 * Values.tyfs)) * 3.14 / 180) * (1 - dip / 90.0)); Ps.Y = (cyCompass - radiusCompass * Math.Cos((double)(Lim360(direction + 180 * Values.tyfs)) * 3.14 / 180) * (1 - dip / 90.0)); Intersection intersection = new Intersection(); TdLine l1 = intersection.CalMidLine(P1, Ps); TdLine l2 = intersection.CalMidLine(P2, Ps); TdPoint Pc = intersection.CalIPoint(l1, l2); double dist = intersection.Distance(Pc, P1); //canvas.DrawCircle((float)Pc.X, (float)Pc.Y, (float)dist, paint);//赤平投影圆弧 //canvas.DrawLine((float)Ps.X, (float)Ps.Y, (float)P0.X, (float)P0.Y, paint);//倾角倾向线 canvas.DrawLine((float)P1.X, (float)P1.Y, (float)P2.X, (float)P2.Y, paint);//走向线 RectF re = new RectF((float)(Pc.X - dist), (float)(Pc.Y - dist), (float)(Pc.X + dist), (float)(Pc.Y + dist)); double[] angle = new double[2]; angle[0] = GetAngle(P2, Pc); angle[1] = GetAngle(P1, Pc); paint.SetStyle(Paint.Style.Stroke); if (Math.Abs(angle[1] - angle[0]) >= 180) //层面赤平投影 { canvas.DrawArc(re, (float)angle[Values.tyfs], (float)(360 - Math.Abs(angle[0] - angle[1])), false, paint); } else { canvas.DrawArc(re, (float)angle[Values.tyfs], (float)(Math.Abs(angle[1] - angle[0])), false, paint); } } }
public StructPlane CutStructPlane(StructPlane structPlane) { Intersection intersection = new Intersection(); TdLine line = intersection.CalLine(structPlane.X1, structPlane.Y1, structPlane.X2, structPlane.Y2); TdLine line2; TdPoint point; bool p1out = false; bool p2out = false; //structPlane.visible1 = 1; //structPlane.visible2 = 1; if (structPlane.X1 < App.left) { line2 = new TdLine { C = 0, B = -1 * App.left }; point = intersection.CalIPoint(line, line2); structPlane.X1 = (float)point.X; structPlane.Y1 = (float)point.Y; structPlane.visible1 = 0; p1out = true; } if (structPlane.X1 > App.right) { line2 = new TdLine { C = 0, B = -1 * App.right }; point = intersection.CalIPoint(line, line2); structPlane.X1 = (float)point.X; structPlane.Y1 = (float)point.Y; structPlane.visible1 = 0; p1out = true; } if (Math.Abs(structPlane.X1 - App.left) < 0.01f || Math.Abs(structPlane.X1 - App.right) < 0.01f) { p1out = true; } if (structPlane.Y1 < App.top) { line2 = new TdLine { C = 1, B = App.top, A = 0 }; point = intersection.CalIPoint(line, line2); structPlane.X1 = (float)point.X; structPlane.Y1 = (float)point.Y; structPlane.visible1 = 0; p1out = true; } if (structPlane.Y1 > App.bottom) { line2 = new TdLine { C = 1, B = App.bottom, A = 0 }; point = intersection.CalIPoint(line, line2); structPlane.X1 = (float)point.X; structPlane.Y1 = (float)point.Y; structPlane.visible1 = 0; p1out = true; } if (Math.Abs(structPlane.Y1 - App.top) < 0.01f || Math.Abs(structPlane.Y1 - App.bottom) < 0.01f) { p1out = true; } if (structPlane.X2 < App.left) { line2 = new TdLine { C = 0, B = -1 * App.left }; point = intersection.CalIPoint(line, line2); structPlane.X2 = (float)point.X; structPlane.Y2 = (float)point.Y; structPlane.visible2 = 0; p2out = true; } if (structPlane.X2 > App.right) { line2 = new TdLine { C = 0, B = -1 * App.right }; point = intersection.CalIPoint(line, line2); structPlane.X2 = (float)point.X; structPlane.Y2 = (float)point.Y; structPlane.visible2 = 0; p2out = true; } if (Math.Abs(structPlane.X2 - App.left) < 0.01f || Math.Abs(structPlane.X2 - App.right) < 0.01f) { p2out = true; } if (structPlane.Y2 < App.top) { line2 = new TdLine { C = 1, B = App.top, A = 0 }; point = intersection.CalIPoint(line, line2); structPlane.X2 = (float)point.X; structPlane.Y2 = (float)point.Y; structPlane.visible2 = 0; p2out = true; } if (structPlane.Y2 > App.bottom) { line2 = new TdLine { C = 1, B = App.bottom, A = 0 }; point = intersection.CalIPoint(line, line2); structPlane.X2 = (float)point.X; structPlane.Y2 = (float)point.Y; structPlane.visible2 = 0; p2out = true; } if (Math.Abs(structPlane.Y2 - App.top) < 0.01f || Math.Abs(structPlane.Y2 - App.bottom) < 0.01f) { p2out = true; } if (p1out) { structPlane.visible1 = 0; } else { structPlane.visible1 = 1; } if (p2out) { structPlane.visible2 = 0; } else { structPlane.visible2 = 1; } return(structPlane); }