• Notice regarding image hosts and attachments. See here.

Algorithm in Java

Associate
Joined
11 Jan 2005
Posts
1,053
Location
Bognor Regis
Can anyone help me I am stumped, I want to convert this algorithm into Java any var names will do:



I have either got it right and its not working or I haven't got it right so I would like to eliminate one of these.

Anyone brave enough?
 
matja said:
i_a = (1/(y_1-y_2))*((i_1*(y_s-y_2))+(i_2*(y_1-y_s)));

Yup Identical to what I had, but it doesn't seem to work, clearly it must be one of my parameters.

Many thanks for your help.
 
Yes it is recursive, it is an algorithm for gouraud shading to calculate the intensity of a colour (i_a) on a line given the y coordinate of both points on the line (y_1 & y_2), the intensity at both these points (i_1 & i_2) and the current scanline (y_s).

The reason I believe it is not working is that the output should logically be a value between i_1 and i_2 however putting a print statement after the algorithm displays that even if the values are:

Code:
i_1 = 200 and i_1 = 255

The result is still i_a = 871

Some of the lines work its odd. :confused:
 
matja said:
Works fine for me :

y_1 = 100; i_1 = 200;
y_2 = 200; i_2 = 255;
y_s = 150;
i_a = (1/(y_1-y_2))*((i_1*(y_s-y_2))+(i_2*(y_1-y_s)));

i_a is 227.5 - half way between 200 and 255, as expected.

Are you using floats?

I think Ive got it, I my y_s wasn't between y_1 and y_2;

Thanks for your help. I may need more help yet.
 
Back
Top Bottom