?
Solved

about FOR - LOOP proble,

Posted on 2004-11-12
6
Medium Priority
?
220 Views
Last Modified: 2010-04-01
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
Comment
Question by:tom_mk
3 Comments
 
LVL 48

Accepted Solution

by:
AlexFM earned 672 total points
ID: 12563420
Loop header should be:

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

Assisted Solution

by:wayside
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

by:pb_india
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

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

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 …
Article by: evilrix
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.

850 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question