1 Attachment(s)

find the coordinates of 12 points of intersection

Hello :)

i hope everyone is doing fine :)

I have a homework for c++,which needs a mathematical solution first,that i found it difficult to find :/...

we have 3 points,each point is emitting 2 lines,we have to find the coordinates of the 12 points of intersection.

(we don't have any value.. the coordinate can be used as (x,y) (x',y') , as for angles, alfa beta gama..

I will really appreciate your help!!

Thanks you in advanced!

evening!Attachment 27641

Re: find the coordinates of 12 points of intersection

What about starting to find the points of intersection of 2 lines?

y=mx+b ,with m the slope =tan of what angle ? :/

i just need the method literary. No numerical values.

Re: find the coordinates of 12 points of intersection

Hi,

You really weren't very precise in your specification of the problem. First given, 3 points and 2 lines passing through each of the points there are a priori 15 possible points of intersection of the lines. Subtracting the 3 intersections of the given points, you get a maximum of 12 additional intersections. There could be 0 additional intersections; for example if the two lines passing through each point are the sides of a triangle. Next, where does the data come from? User input, read from a file, randomly generated? Since you didn't specify, I'll make up the form of the data.

Any line has equation of the form Ax+By+C=0. Given that a point (x1,y1) is a point on the line, you need an additional point (x2,y2) to specify the line. So I would define a class Line with (private) members x1,y1,x2,y2 all doubles with a constructor which has parameters for the values of these members. Also I would have members A,B and C the coefficients of the equation of the line. Your constructor should set the value of these coefficients:

A=y1-y2, B=x2-x1 and C=x1*y2-y1*x2.

Also I would have a method of class Line:

int intersect(const Line& L, Point* p);

This method returns false if the Line L is parallel to this line. Otherwise it returns true and the Point p is set to the intersection of the lines. The lines are parallel iff det=A*L.B-B*L.A==0 (you may want to say the lines are parallel if det is very small in magnitude; problems with round off error using doubles really have to be addressed).

Assuming the lines are not parallel,

p->x=(-C*L.B+B*L.C)/det and p->y=(-A*L.C+C*L.A)/det

Next I would have an array allLines of Lines with the x1,y1 fields of allLines[0] the same as the x1,y1 fields of allLines[1], etc. Also an array allIntersections of Points. Generalizing your situation to n points and 2*n lines, the intersection computation could go something like:

intersections=0;

for (i=0;i<2*n-2;i+=2) {

for (j=i+2;j<n;j++) {

if (allLines[i].intersect(allLines[j],&allIntersections[intersections]) {

intersections++;

}

if (allLines[i+1].intersect(allLines[j],&allIntersections[intersections]) {

intersections++;

}

}

}

I hope this helps. Sorry, this editor ignores indentation so the code fragment may be a little hard to read.