equation of line , without using a slope ( determinants)

Started by
1 comment, last by Fil 19 years, 2 months ago
i , in a previous post have shown my method for using determinants to check for intersection of two lines. this is how i am getting the two line equations

ad = p1.Yval - p2.Yval;
			bc = p2.Xval - p1.Xval;

			c = ad* p1.Xval + bc*p1.Yval;

			//line2
			double ad2,bc2;
			double c2;
			
			ad2 = p3.Yval - p4.Yval;
			bc2 = p4.Xval - p3.Xval;

			c2 = ad* p3.Xval + bc*p3.Yval;
my algorithm is not working at all and the only place i can see that it might not be funcitioning is in getting the line equations. does this look ok, or do you have any suggestions?
I currently only use c# and directX9, in case its relivant and i didnt mention it in the post
Advertisement
Looks right to me. As a sanity check you can always put your equation into the more intuitive (at least for me) slope-intercept form and you'd get:
p1.Yval = (-ad/bc)p1.Xval + (c/bc)

Which is essentially:
y = (p2.Yval - p1.Yval)x/(p2.Xval - p1.Xval) + c/(p2.Xval - p1.Xval)

Which is correct as far as I know.
You can make use of parametric equation for the lines.
Search for LINES_SEG_INT_2D in the source "geometry.f90" you find in this page (it's in cobol, but it easy to read and well commented).

Hope this helps!
Fil (il genio)

This topic is closed to new replies.

Advertisement