walid

walid

  • NA
  • 4
  • 0

Display problem with zero points

May 28 2007 2:05 PM
Hi, I wrote a program in C# to display zero points and the coordinates x and y in a graphic chart. The zero points are shown on the console but not in the diagram. I would like to display the numbers (zero points)also in the diagram. The program is already working on the console, using console.writeline. How does this work on GDI? For reference, see my program below: using System; using System.Collections; using System.ComponentModel; using System.Data; using System.Drawing; using System.Text; using System.Windows.Forms; namespace WindowsApplication1 { public partial class Form1 : Form { private double Linkerwert = 0, Rechterwert = 1; private float x1, x2, y1, y2; private double[] Array1; private double[] Array2; private int index1, index2; public Form1() { InitializeComponent(); } private void progrmmToolStripMenuItem_Click(object sender, EventArgs e) { } private void button1_Click(object sender, EventArgs e) { this.Refresh(); this.Linkerwert = Convert.ToDouble(textBox1.Text); this.Rechterwert = Convert.ToDouble(textBox2.Text); } private void panel2_Paint(object sender, PaintEventArgs e) { ZeichneLinien(sender, e); ZeichneKurve(sender, e); } private void ZeichneLinien(object sender, PaintEventArgs e) { e.Graphics.PageUnit = GraphicsUnit.Millimeter; Pen Pen1 = new Pen(Color.Blue, 0.5F); Pen Pen2 = new Pen(Color.Black, 0.1F); this.x1 = 0.0F; this.y1 = 60F; this.x2 = 210F; this.y2 = this.y1; e.Graphics.DrawLine(Pen1, x1, y1, x2, y2); // e.Graphics.DrawString this.x1 = 80F; this.y1 = 0.0F; this.x2 = this.x1; this.y2 = 125F; e.Graphics.DrawLine(Pen1, x1, y1, x2, y2); for (float i = 0; i <= this.panel2.Size.Width; i = i + 5) { e.Graphics.DrawLine(Pen2, i, this.panel2.Size.Height, i, 0.0F); } for (float i = 0; i <= this.panel2.Size.Height; i = i + 5) { e.Graphics.DrawLine(Pen2, 0.0F, i, this.panel2.Size.Width, i); } } public void ZeichneKurve(object sender, PaintEventArgs e) { e.Graphics.PageUnit = GraphicsUnit.Millimeter; ArrayList points = new ArrayList(); int Zahl1 = 0, Zahl2 = 0, groeße; float Mittex = 80, Mittey = 60; Anzeigen(); for (double i = this.Linkerwert; i <= this.Rechterwert; i += 0.01) points.Add(new PointF((float)(((this.Array1[Zahl1++] * 30) + Mittex)), (float)(((this.Array2[Zahl2++] * -1) + Mittey)))); groeße = points.Count; PointF[] pt = new PointF[groeße]; pt = (PointF[])points.ToArray(typeof(PointF)); e.Graphics.DrawCurve(new Pen(Color.Red, 0.3F), pt); } public void Anzeigen() { this.index1 = Convert.ToInt32((this.Rechterwert + Math.Abs(this.Linkerwert)) * 100); this.index2 = Convert.ToInt32((this.Rechterwert + Math.Abs(this.Linkerwert)) * 100); Array1 = new double[index1]; Array2 = new double[index2]; int Zahl1 = 0, Zahl2 = 0; for (double i = this.Linkerwert; i <= this.Rechterwert; i += 0.01) { if (i == 0) { this.Array1[Zahl1++] = 0; this.Array2[Zahl2++] = 30; } else { this.Array1[Zahl1++] = i; this.Array2[Zahl2++] = MyFunction(i); } } } public double MyFunction(double x) { return Math.Sin(30 * (x)) / x; } private void benndenToolStripMenuItem_Click(object sender, EventArgs e) { Application.Exit(); } private void infoToolStripMenuItem_Click(object sender, EventArgs e) { MessageBox.Show("Nullstellen Programm Version 1.1.0 \n Autor: Walid El Sayed Aly \n 28.05.2007"); } private void panel1_Paint(object sender, PaintEventArgs e) { } public double Nullstellen_Funktion(double FirstValue, double SecondValue) { double Exactly = 0.00000001; double Nullstelle = (FirstValue + SecondValue) / 2; while (Math.Abs(SecondValue - FirstValue) >= Exactly && MyFunction(Nullstelle) != 0) { if (MyFunction(FirstValue) * MyFunction(Nullstelle) < 0) // Unter die x-Achse { SecondValue = Nullstelle; } else // Ueber die x-Achse { FirstValue = Nullstelle; } Nullstelle = (FirstValue + SecondValue) / 2; } return Nullstelle; } public void Output() { int Numerator = 1; for (double i = this.Linkerwert; i <= this.Rechterwert; i += 0.01) { if ((MyFunction(i) > 0 && MyFunction(i + 0.01) < 0) || //Wenn es einen Vorzeichenewechsel gibt (MyFunction(i) < 0 && MyFunction(i + 0.01) > 0)) { double MyNullstellen = Nullstellen_Funktion(i, 0.01 + i); // Nullstellen berechnen ///-->>> Console.Writeline("[" + Numerator + "]" + "\tDie Nullstelle ist " + Math.Round((MyNullstellen), 15)); Numerator++; } } } } }