Posted by
Robert Dougherty on
Dec 28, 2009; 4:55am
URL: http://imagej.273.s1.nabble.com/Nelp-needed-tp3689904p3689905.html
Dilip,
Here is my understanding. I'm sure it will be corrected if necessary.
Suppose you want to draw a line from (x1,y2) to (x2,y2). First determine which is larger, deltaX = |x2-x1| or deltaY = |y2 - y1|. If deltaX is larger, then our line is going to have deltaX+1 pixels, with x running from x1 to x2. For each x value on the line (segment), the corresponding value of y is computed by interpolating:
y = (int)( y1(x2 - x)/(x2 - x1) + y2(x - x1)/(x2 - x1) + 0.5)
If deltaY is larger, then y runs from y1 to y2, and each x is computed to by a formula analogous to the above with x and y interchanged. If deltaX = deltaY, then do it either way. If the largest delta is 0, then just draw one pixel.
In ImageJ programming, you should not have to do this computation if all you want to do is draw a line. There are ImageJ and AWT methods to handle it.
Bob
On Dec 27, 2009, at 8:16 PM, Dilip Baluguri wrote:
> I just want to know how a line is drawn between two points. What is I need
> is how the intermediate pixels are choosen while drawing a line. Given two
> poins A(10,20) and B(40,200) how intermediate pixels are choosen.Any help is
> appreciated.
> Thanks in advance.
>
>
>
> Dilip Kumar Baluguri
> CWID: 50044123
> Graduate Student- Computer Science
> TAMU-Commerce
> (630)383-9112
>
> Mike Ditka <
http://www.brainyquote.com/quotes/authors/m/mike_ditka.html> -
> "If God had wanted man to play soccer, he wouldn't have given us arms."
Robert Dougherty, Ph.D.
President, OptiNav, Inc.
4176 148th Ave. NE
Redmond, WA 98052
(425)891-4883
FAX (425)467-1119
www.optinav.com
[hidden email]