getting values from specific element in an array

Hi people

This question is not Java-specific, but since I'm doing this in Java, perhaps you could help me.

I have a large 1-dimensional byte array of size n^2. The array is displayed on screen as a n x n image, where each pixel color is determined by the value of the corresponding array element.

The user clicks, drags and releases the mouse on the image, thereby drawing a line from (x1, y1) to (x2, y2).

I now need to check which pixels of the image are touched by that line, so that i may obtain the values of those array elements.

I've tried y=mx+b but run into problems (i'm not really all that algebraically-minded). I hope someone here might be, or may have had a similar problem, and could help me.

Many thanks in advance

Hennie

[789 byte] By [mokopaa] at [2007-10-2 5:30:56]
# 1

Go see

http://www.cs.unc.edu/~mcmillan/comp136/Lecture6/Lines.html

A simple search on the web would have given you the answer. Now if you want anti-aliasing I believe we will have to go to another site. I am sure this is homework but the answer is from a school so what the heck. One thing if you use the exact algorithm without changes I suspect your professor might figure out that you are copying.

MexicoClivea at 2007-7-16 1:41:56 > top of Java-index,Java Essentials,Java Programming...
# 2

Wow. Brilliant.

It is in fact not homework at all! I am not a student, but a professional 3D artist for about 10 years now who's starting to move over to programming, and this little problem cropped up since I am doing a lot of graphics programming at the moment (obvious, isn't it...?). What really freaked me out is that, on this particular project, I had actually managed to grasp the Brownian motion and itterative phase shift fractal algorithms quite easily, but this darn LINE thing had me floored! Incredible, but true.

Thank you very much for your link. It not only solved my problem, but also opened a number of other doors for me to explore...problems I will undoubtedly come across later on.

mokopaa at 2007-7-16 1:41:56 > top of Java-index,Java Essentials,Java Programming...