Problem mit Transformationen und PageUnit Einheiten
-
hi,
ich habe ein Programm zur grafischen Kräftezerlegung an der schiefen Ebene geschrieben. Es ist noch in der Test und weiterentwicklungsphase und es ergibt sich folgendes Problem :ich habe den Null punkt durch TranslateTransform auf 100,100 gesetzt ( alles funktioniert in Millimetern ) dann werden 13 Punkte errechnet p1,p2,...
Grfikausgegeben und Linien gezeichnet... wunderbar. Jetzt will ich den Ursprung des Koordinatensystems auf den Punkt p9 setzen, wie mach ich das ?
TranslateTransform( p9.X, p9.Y ) funktioniert nicht und ich glaube ich muss das umrechnen weis aber nicht wieausserdem ist da noch das Problem mit dem Drucker... die Grafik soll nämlich druckbar sein
( ahja das ganze dient dazu weil ich dann mit RotateTransform um den "neuen Null-Punkt" drehen möchte um Pfeile auf die verschiedenen Linien zu zeichnen ! Oder ist das ein ganz falscher Ansatz ? )
Wenn es Hilft bin ich auch bereit den Code zu posten...
-
da scheinbar keiner mir helfen kann / will / tut poste ich mal den Quellcode da die Frage nicht so ganz übersichtlich ist:
public partial class Form1 : Form { Pen blackpen = new Pen(Color.Black, 0.25f); Pen redpen = new Pen(Color.Red, 0.5f); Pen greenpen = new Pen(Color.Green, 0.5f); Pen bluepen = new Pen(Color.Blue, 0.5f); Brush brush = Brushes.Black; Font myfont = new Font("Times New Roman", 14); float Angle = 30; float Weight = 50; float FZ = 0; float FH = 0; float FN = 0; float value1 = 0; float value2 = 0; int ScaleFactor = 1; Rectangle inforect; SimpleDialogBox dlg = new SimpleDialogBox(); NumericUpDown updown1 = new NumericUpDown(); NumericUpDown updown2 = new NumericUpDown(); public Form1() { InitializeComponent(); ResizeRedraw = true; Text = " 1st C# Prog"; updown1.Parent = this; updown1.Location = new Point(0, 0); updown1.Size = new Size(48, 12); updown1.TextAlign = HorizontalAlignment.Right; updown1.ValueChanged += new EventHandler(UpDownOnValueChanged); updown1.DecimalPlaces = 0; updown1.Increment = 1m; updown1.Minimum = 1; updown1.Maximum = 89; updown2.Parent = this; updown2.Location = new Point(0, 30); updown2.Size = new Size(48, 12); updown2.TextAlign = HorizontalAlignment.Right; updown2.ValueChanged += new EventHandler(UpDownOnValueChanged); updown2.DecimalPlaces = 1; updown2.Increment = 1.0m; updown2.Minimum = 0.1m; updown2.Maximum = Decimal.MaxValue; inforect = new Rectangle( new Point(100, 100), new Size(Font.Height*30,Font.Height * 10)); // Menü MenuItem miAttitudes = new MenuItem("&Einstellungen", new EventHandler(MenuAttitudesOnClick), Shortcut.CtrlE); MenuItem miFile = new MenuItem("&Datei", new MenuItem[] { miAttitudes }); Menu = new MainMenu(new MenuItem[] { miFile }); } protected override void OnResize(EventArgs e) { base.OnResize(e); } protected virtual void DoPage(Graphics grfx ) { if ( dlg.AA == true) { grfx.SmoothingMode = SmoothingMode.HighQuality; } if ( dlg.pixmode == true) { grfx.PixelOffsetMode = PixelOffsetMode.HighQuality; } grfx.TranslateTransform(100f, 100f); // Nullpunkt auf 100,100 MM setzen //AutoScrollMinSize = new Size(ClientRectangle.Width, (int)weightconverter(Weight)); grfx.PageUnit = GraphicsUnit.Millimeter; grfx.PageScale = 1; PointF p1 = new PointF(0, 0); PointF p2 = new PointF(120, 0); grfx.DrawLine(blackpen, p1, p2); PointF p3 = new PointF(p2.X, 0); p3.Y = -((float)Math.Tan(Math.PI * Angle / 180) * (p2.X - p1.X) + 0); grfx.DrawLine(blackpen, p1, p3); PointF p4 = new PointF(p1.X - 20, 0); //PointF p5 = new PointF(p4.X + 140, 0); PointF p6 = new PointF(p2.X, -((float)Math.Tan(Math.PI * Angle / 180) * (p2.X - p4.X) + 0)); grfx.DrawLine(blackpen, p4, p6); PointF p7 = new PointF(p4.X, p4.Y + weightconverter(Weight)); PointF p8 = new PointF(p6.X, p6.Y + weightconverter(Weight)); //grfx.DrawLine(blackpen, p7, p8); PointF p9 = new PointF(60, -((float)Math.Tan(Math.PI * Angle / 180) * 80)); PointF p10 = new PointF(p9.X, p9.Y + weightconverter(Weight)); grfx.DrawLine(blackpen, p9, p10); FH = (float)Math.Sin(Angle * Math.PI / 180) * weightconverter(Weight); FZ = -FH; value1 = FH * (float)Math.Sin(Angle * Math.PI / 180); value2 = FH * (float)Math.Cos(Angle * Math.PI / 180); PointF p11 = new PointF(p9.X - value2, p9.Y + value1); grfx.DrawLine(redpen, p9, p11); grfx.DrawLine(blackpen, p11, p10); value1 = FH * (float)Math.Sin(Angle * Math.PI / 180); value2 = FH * (float)Math.Cos(Angle * Math.PI / 180); PointF p12 = new PointF(p9.X + value2, p9.Y - value1); grfx.DrawLine(greenpen, p9, p12); PointF p13 = new PointF(p12.X , p12.Y + weightconverter(Weight)); grfx.DrawLine(bluepen, p9, p13); grfx.DrawLine(blackpen,p10,p13); DrawVerticalArrowDown(p10, grfx); if ( dlg.letters == true ) { grfx.DrawString("A", myfont, brush, p1); grfx.DrawString("B", myfont, brush, p2); grfx.DrawString("C", myfont, brush, p3); grfx.DrawString("D", myfont, brush, new PointF(p4.X, p4.Y - Font.Height / 2));// grfx.DrawString("E", myfont, brush, new PointF(p6.X,p6.Y-Font.Height/2));// grfx.DrawString("F", myfont, brush, new PointF(p9.X, p9.Y - Font.Height / 2));// grfx.DrawString("G", myfont, brush, p10); grfx.DrawString("H", myfont, brush, new PointF(p11.X, p11.Y - Font.Height / 2));// grfx.DrawString("Z", myfont, brush, new PointF(p12.X, p12.Y - Font.Height / 2));// grfx.DrawString("N", myfont, brush, p13); } FN = (float)Math.Cos(Angle * Math.PI / 180) * Weight; grfx.ResetTransform(); // !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! grfx.TranslateTransform(50,50); grfx.DrawLine(blackpen, new PointF(0, 0), new PointF(10, 0)); // !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! grfx.PageUnit = GraphicsUnit.Pixel; string str = String.Format("1 Millimeter = {0} Newton\n\nHangabtriebskraft [FH]: {1} Newton\n\nNormalkraft [FN]: {2} Newton", ScaleFactor, FH * ScaleFactor, FN); grfx.DrawString(str, myfont, brush, inforect.Location); grfx.DrawRectangle(blackpen, inforect); } protected override void OnPaint(PaintEventArgs pea) { Graphics grfx = pea.Graphics; DoPage(grfx); } void UpDownOnValueChanged(Object obj,EventArgs e) { Angle = (float) updown1.Value; Weight = (float)updown2.Value; Invalidate(); } protected float weightconverter(float N) { int rest; int i = 2; ScaleFactor = 1; if (N > 3500) { N = N / 10; ScaleFactor = ScaleFactor * 10; } if (N > 300) { N = N / 10; ScaleFactor = ScaleFactor * 10; } if (N > 150) { for (; i < 15; i++) { rest = (int)N % i; if (rest == 0) { N = N / i; ScaleFactor = ScaleFactor * i; break; } } } return N; } protected override void OnClick(EventArgs e) { base.OnClick(e); if ( dlg.print == true) { PrintDocument prndoc = new PrintDocument(); prndoc.DocumentName = Text; prndoc.PrintPage += new PrintPageEventHandler(PrintDocumentOnPrintPage); prndoc.Print(); // Kein Drucker installiert } } protected override void OnMouseUp(MouseEventArgs e) { base.OnMouseUp(e); inforect.Location = e.Location; Invalidate(); } void PrintDocumentOnPrintPage(Object obj, PrintPageEventArgs ppea) { Graphics grfx = ppea.Graphics; DoPage(grfx); } void MenuAttitudesOnClick(object obj, EventArgs ea) { dlg.ShowDialog(); Invalidate(); } void DrawVerticalArrowDown( PointF pt, Graphics grfx) { PointF[] pts = new PointF[3]; pts[0] = new PointF(pt.X - 1, pt.Y - 5); pts[1] = new PointF(pt.X + 1, pt.Y - 5); pts[2] = pt; grfx.FillPolygon( Brushes.Black, pts); } }
-
Das Problem hat sich erledigt, bin von selbst drauf gekommen ! ! !