PDA

View Full Version : ایجاد خط اعشاری



vinnie-paz
پنج شنبه 20 مهر 1391, 15:24 عصر
سلام دوستان من میخوام با استفاده از فرمول ریاضی خط اعشاری درست کنم گیج شدم عیب کارم کجاست یعنی؟

private void button2_Click(object sender, EventArgs e)
{



x1 = Convert.ToInt32(textBox1.Text);
y1 = Convert.ToInt32(textBox2.Text);
x2 = Convert.ToInt32(textBox3.Text);
y2 = Convert.ToInt32(textBox4.Text);
gh =(y2-y1)*(1.0)/(x2-x1);
if (Math.Abs(y2 - y1) < Math.Abs(x2 - x1))
{
int x;
double y;



for (x = x1; x <= x2; x++)
{
y = (gh * x + y1 - gh * x1);
bmp.SetPixel(x, (int)(Math.Round(y)), Color.Red);
}
}
else

{
double x;
int y;
for (x = x1; x <= x2; x++)
{
y = (gh * x + y1 - gh * x1);
bmp.SetPixel(x, (int)(Math.Round(y)), Color.Red);
}
}


pictureBox1.Image = bmp;




}
}
}