Loop Issues

Hi, new to the world of C++!

I'm trying to write a program to compute the intersection angle between two sloped lines from a set of data given as an array. There are in total 8 lines making 4 cases to solve.
The array looks like this (well, this is the data table it was made from, the array is just numbers);

Line A (|) Line B
Xa1 Ya1 Xa2 Ya2 (|) Xb1 Yb1 Xb2 Yb2
3.5 4.75 -2.5 5. (|) 6. 3. -8. 2.
4.5 3.25 5.25 -4. (|) 3.5 -4. 6.5 21.
5. -7.5 3. 8.5 (|) 3.75 -5.625 2.25 6.375
-10.25 5.25 -4.5 3.25 (|) 4.5 12.5 8.75 -2.75

and assigned as follows;

xa1, ya1, xa2, ya2, xb1, yb1, xb2, yb2

Using some simple math I computed the slopes m1 and m2.

m1=(ya2-ya1)/(xa2-xa1)
m2=(yb2-yb1)/(xb2-xb1)

Now I have my problem. I know how to determine the angle between the intersecting lines, and have written my "if" statement;

if(m1==m2)
angle=0.0;
else if(m1*m2==-1.)
angle=90.0;
else
angle=atan((m1-m2)/(1.+(m1*m2)));

But, I know I have to create a loop here... somewhere. I have to calculate the remaining slopes from the data, and then put them through the "if" statement. This is where I become confused!

Please help! Thank you!
Hi.
You need to 'step back' from the detail a little, and consider the main steps to do this.
EG:
1) Get coordinates of first pair of lines
2) Calulate Slopes of pair of lines
3) Calculate intersection of pair of lines
4) Repeat for next pair of lines.
You have alredy figured steps 2 & 3 - so all you have to do is write a loop which sets your 'current pair of lines' varaibles, calls the code for slope and intersection, then repeats.
I would make the two calculations functions to make the whole program clearer to read.



Sorry, I'm still lost.
When I'm getting the data is there a special way?
Since I inputted it from a data file in an array form at was I supposed to write it differently?

ifstream slope_a;
slope_a.open ("a3.dat");
slope_a >>xa1 >>ya1 >>xa2 >>ya2 >>xb1 >>yb1 >>xb2 >>yb2;
Just put the input at the start of a loop, eg;
1
2
3
4
5
6
7
8
ifstream slope_a;
slope_a.open ("a3.dat");
while (!slope_a.eof())
{
   slope_a >>xa1 >>ya1 >>xa2 >>ya2 >>xb1 >>yb1 >>xb2 >>yb2;
   //Calculate Slope
   //Calculate Intersection
}

When it goes through the loop the second time it will resset the coordinates and so perform the calculations on the new numbers.
Topic archived. No new replies allowed.