Schrägen Pfeil malen, Probleme...

Diese Seite verwendet Cookies. Durch die Nutzung unserer Seite erklären Sie sich damit einverstanden, dass wir Cookies setzen. Weitere Informationen

  • Schrägen Pfeil malen, Probleme...

    Hallo.
    Mal wieder stoße ich auf ein Problem dass ich nun nach einigen Anläufen nicht allein schaffe.
    Es handelt sich wahrscheinlich nur um ein mathematisches Problem, aber Ansätze habe ich keine weiter gefunden.
    Anfangs habe ich versucht über den tangens zu gehen um dann die stelle zu ermitteln, wo hin gezeichnet werden soll und diese dann dazu addiert... nur funktioniert dies leider nicht.
    Hier erstmal der lauffähige Quellcode, den extra eingekürzt habe, damit ich ihn hier posten kann.
    Wie man sieht klappt das so wie ich es mache nicht ganz...

    Quellcode

    1. using System;
    2. using System.Collections.Generic;
    3. using System.ComponentModel;
    4. using System.Data;
    5. using System.Drawing;
    6. using System.Text;
    7. using System.Windows.Forms;
    8. namespace WindowsFormsApplication3
    9. {
    10. public class Form1 : Form
    11. {
    12. /// <summary>
    13. /// Erforderliche Designervariable.
    14. /// </summary>
    15. private System.ComponentModel.IContainer components = null;
    16. /// <summary>
    17. /// Verwendete Ressourcen bereinigen.
    18. /// </summary>
    19. /// <param name="disposing">True, wenn verwaltete Ressourcen gelöscht werden sollen; andernfalls False.</param>
    20. protected override void Dispose(bool disposing)
    21. {
    22. if (disposing && (components != null))
    23. {
    24. components.Dispose();
    25. }
    26. base.Dispose(disposing);
    27. }
    28. #region Vom Windows Form-Designer generierter Code
    29. /// <summary>
    30. /// Erforderliche Methode für die Designerunterstützung.
    31. /// Der Inhalt der Methode darf nicht mit dem Code-Editor geändert werden.
    32. /// </summary>
    33. private void InitializeComponent()
    34. {
    35. this.pictureBox1 = new System.Windows.Forms.PictureBox();
    36. this.button1 = new System.Windows.Forms.Button();
    37. ((System.ComponentModel.ISupportInitialize)(this.pictureBox1)).BeginInit();
    38. this.SuspendLayout();
    39. //
    40. // pictureBox1
    41. //
    42. this.pictureBox1.Location = new System.Drawing.Point(12, 12);
    43. this.pictureBox1.Name = "pictureBox1";
    44. this.pictureBox1.Size = new System.Drawing.Size(260, 240);
    45. this.pictureBox1.TabIndex = 0;
    46. this.pictureBox1.TabStop = false;
    47. //
    48. // button1
    49. //
    50. this.button1.Location = new System.Drawing.Point(197, 258);
    51. this.button1.Name = "button1";
    52. this.button1.Size = new System.Drawing.Size(75, 23);
    53. this.button1.TabIndex = 1;
    54. this.button1.Text = "button1";
    55. this.button1.UseVisualStyleBackColor = true;
    56. this.button1.Click += new System.EventHandler(this.button1_Click);
    57. //
    58. // Form1
    59. //
    60. this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
    61. this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
    62. this.ClientSize = new System.Drawing.Size(284, 288);
    63. this.Controls.Add(this.button1);
    64. this.Controls.Add(this.pictureBox1);
    65. this.Name = "Form1";
    66. this.Text = "Form1";
    67. ((System.ComponentModel.ISupportInitialize)(this.pictureBox1)).EndInit();
    68. this.ResumeLayout(false);
    69. }
    70. #endregion
    71. private System.Windows.Forms.PictureBox pictureBox1;
    72. private System.Windows.Forms.Button button1;
    73. public Form1()
    74. {
    75. InitializeComponent();
    76. }
    77. private Bitmap bmp;
    78. private Graphics PrintHandler;
    79. private void button1_Click(object sender, EventArgs e)
    80. {
    81. Pen p = new Pen(Color.Red, 1);
    82. Pen p2 = new Pen(Color.Blue, 2);
    83. this.bmp = new Bitmap(pictureBox1.Width, pictureBox1.Height);
    84. pictureBox1.Image = bmp;
    85. PrintHandler = Graphics.FromImage(pictureBox1.Image);
    86. double durchmesser = 11d;
    87. double Vx = 21.213;
    88. double Vy = -18.134;
    89. double yVorzeichenVerschiebung = Vy;
    90. double xStart = (durchmesser - 1d) / 2d;
    91. double yStart = 0d - yVorzeichenVerschiebung + (durchmesser - 1d) / 2d;
    92. double xStop = Vx;
    93. double yStop = durchmesser / 2d;
    94. Point startPoint = new Point((int)xStart, (int)yStart);
    95. Point endPoint = new Point((int)xStop, (int)yStop);
    96. PrintHandler.DrawLine(p2, startPoint, endPoint);
    97. if (yVorzeichenVerschiebung == 0)
    98. {
    99. /*e.Graphics.DrawLine(p2, endPoint, new Point(endPoint.X - 10, endPoint.Y));
    100. e.Graphics.DrawLine(p2, endPoint, new Point(endPoint.X, endPoint.Y - 10));*/
    101. /*e.Graphics.DrawLine(p2, endPoint, new Point(endPoint.X - 10, endPoint.Y));
    102. e.Graphics.DrawLine(p2, endPoint, new Point(endPoint.X, endPoint.Y - 10));*/
    103. //Console.Out.WriteLine(1);
    104. }
    105. else
    106. {
    107. // Ansatz über winkel klappt irgendwie nicht...
    108. /*double test;
    109. test = Math.Tan(Math.PI * 45 / 180) * Math.Sqrt(Math.Pow(endPoint.X, 2d) * Math.Pow(endPoint.Y, 2d));
    110. */
    111. PrintHandler.DrawLine(p2, endPoint, new Point(endPoint.X - 10, endPoint.Y - 10));
    112. PrintHandler.DrawLine(p2, endPoint, new Point(endPoint.X - 5, endPoint.Y + 10));
    113. }
    114. }
    115. /// <summary>
    116. /// Der Haupteinstiegspunkt für die Anwendung.
    117. /// </summary>
    118. [STAThread]
    119. static void Main()
    120. {
    121. Application.EnableVisualStyles();
    122. Application.SetCompatibleTextRenderingDefault(false);
    123. Application.Run(new Form1());
    124. }
    125. }
    126. }
    Alles anzeigen


    Wenn jemand weiß/herausfindet, wie ich den Quellcode anpassen muss, damit der Pfeil auch aussieht wie ein Pfeil, dem wäre ich sehr verbunden, wenn er dies posten könnte, da ich wie schon erwähnt nicht hinter die Formel komme, dies mir richtig darstellen würde.


    Danke.
    Blackskyliner

    Dieser Beitrag wurde bereits 2 mal editiert, zuletzt von Blackskyliner ()