Coordinator [pls help]

  • Thread starter Thread starter MAY
  • Start date Start date
M

MAY

Hi,

In a form, i draw a straight line, the start point is, for example (23, 43)
and the end point is (243, 342). I want to check each points on that
straight line as to perform some GDI+ calculation, what equation can do
that? (as i know there has an equation called "straight line equation" but
dont know how to use it) Or there have other alternatives? how can i do
that? Can post some simple code? Thx millions.

Regards,

MAY
 
MAY said:
Hi,

In a form, i draw a straight line, the start point is, for example (23, 43)
and the end point is (243, 342). I want to check each points on that
straight line as to perform some GDI+ calculation, what equation can do
that? (as i know there has an equation called "straight line equation" but
dont know how to use it) Or there have other alternatives? how can i do
that? Can post some simple code? Thx millions.

Regards,

MAY

The first problem is definition: exactly when is a point "on the line"?
Do you define points with integer coordinates or with floats (in .Net you
have both Point and PointF)?
With "the line" do you mean the mathematical line through those two
points or do you mean the collection of pixels used to render the
mathematical line in a specific width? (what about anti-aliasing,
where a pixel can be "partially-used"?)

Hans Kesting
 
:
Hi,

In a form, i draw a straight line, the start point is, for example (23, 43)
and the end point is (243, 342). I want to check each points on that
straight line as to perform some GDI+ calculation, what equation can do
that? (as i know there has an equation called "straight line equation" but
dont know how to use it) Or there have other alternatives? how can i do
that? Can post some simple code? Thx millions.

Hi,

Have you had a look on my answer in your last thread ?
 
hi all,

I want get points of a line (interger) and the "line" is mathematical line.
I have written a code but it cant do what i expected. Here is the part of
the code;

MAY


//set points
int x1=pt1.X , y1=pt1.Y ;
int x2=pt2.X , y2=pt2.Y;
//start and end point
Point s;
Point e;
//set the left hand side point as start
if(x1<x2)
{
s=new Point(x1, y1);
e=new Point(x2, y2);
}
else
{
s=new Point(x2, y2);
e=new Point(x1, y1);
}
//slope
long m=0;

//calculate slope
if((e.Y - s.Y )!=0 && (e.X -s.X)!=0)
{
try
{
m=(e.Y - s.Y )/(e.X - s.X);
}
catch(Exception edx)
{
Console.WriteLine("Dividen by zero!");
}
}
//calculate y-intersect
long b=(s.Y )-(m * s.X);

//get all points on this line
for(int i=s.X ; i<=e.X ; i++)
{
long j=(m * i) +b;

//point(i, j)
this.checkpoint(new Point(i, Convert.ToInt32(j))));

}

}
 
Back
Top