Solved

# about FOR - LOOP proble,

Posted on 2004-11-12
Medium Priority
220 Views
hi

i need to have s.t like this
i know that this is not the right approach to do
however, i don't know how to get it work

thx
TOm

for(int cur = 0 && int cur2 = 0 ; cur <= 1 && cur2 <= (x2-x1); cur = cur + d1 && cur2++)
{
//for(int T = 0; T <= 1 ; T = T + ((fc2[0] - fc1[0]) / (x2 - x1)) )
//{
int T1 = ((fc2[0] - fc1[0]) / (x2 - x1));
int T2 = ((fc2[1] - fc1[1]) / (x2 - x1));
int T3 = ((fc2[2] - fc1[2]) / (x2 - x1));

runX = x1 + ((x2 - x1) * cur);
runY = y1 + ((y2 - y1) * cur);

runC1 = fc1[0] + ( (fc2[0] - fc1[0]) * (T1 * cur2) );
runC2 = fc1[1] + ( (fc2[1] - fc1[1]) * (T2 * cur2) );
runC3 = fc1[2] + ( (fc2[2] - fc1[2]) * (T3 * cur2) );

SetPixel(runX,runY,runC1,runC2,runC3);
//}

}
0
Question by:tom_mk

LVL 48

Accepted Solution

AlexFM earned 672 total points
ID: 12563420

for(int cur = 0, int cur2 = 0 ; cur <= 1 && cur2 <= (x2-x1); cur = cur + d1, cur2++)
0

LVL 14

Assisted Solution

wayside earned 664 total points
ID: 12565207
>                   int T1 = ((fc2[0] - fc1[0]) / (x2 - x1));

Note you have a potential divide-by-zero problem here. If x2 = x1 at the start of your for loop, you will crash.
0

LVL 2

Assisted Solution

pb_india earned 664 total points
ID: 12568647
Try this:
int T1=0,T2=0,T3=0;
for(int cur = 0, int cur2 = 0 ; cur <= 1 && cur2 <= (x2-x1); cur = cur + d1, cur2++) /*Like Alex suggested*/
{

if((x2-x1)>0){
T1 = ((fc2[0] - fc1[0]) / (x2 - x1));
T2 = ((fc2[1] - fc1[1]) / (x2 - x1));
T3 = ((fc2[2] - fc1[2]) / (x2 - x1));
}
else{
//Do error catching and resolution.
}
runX = x1 + ((x2 - x1) * cur);

runY = y1 + ((y2 - y1) * cur);

runC1 = fc1[0] + ( (fc2[0] - fc1[0]) * (T1 * cur2) );
runC2 = fc1[1] + ( (fc2[1] - fc1[1]) * (T2 * cur2) );
runC3 = fc1[2] + ( (fc2[2] - fc1[2]) * (T3 * cur2) );

SetPixel(runX,runY,runC1,runC2,runC3);
}
0

## Featured Post

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Container Orchestration platforms empower organizations to scale their apps at an exceptional rate. This is the reason numerous innovation-driven companies are moving apps to an appropriated datacenter wide platform that empowers them to scale at a …
Looking for a way to avoid searching through large data sets for data that doesn't exist? A Bloom Filter might be what you need. This data structure is a probabilistic filter that allows you to avoid unnecessary searches when you know the data defin…
The goal of the video will be to teach the user the difference and consequence of passing data by value vs passing data by reference in C++. An example of passing data by value as well as an example of passing data by reference will be be given. Bot…
The viewer will learn additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.
###### Suggested Courses
Course of the Month15 days, 22 hours left to enroll