Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

[Math] Finding the intersection of two lines

Guest
Dec 24, 2007 Dec 24, 2007
Does anyone here happen to know how to find the intersection of two lines? kglad, perhaps?

My situation is one or both of two possible scenarios. The difference in these two scenarios is how the lines are defined, and I am able to accommodate either:

Scenario 1: To define the two lines I have one point each, thus two known points, and with those points a known angle ranging from -180 to 180 -- this is one point and one angle per line. Illustrated here:
http://abeall.com/files/temp/vector.intersect.gif
(p3 in blue is the unknown point to be solved)
The angles face in a direction such that the lines will intersect, ie the intersection won't happen in the opposite direction of the angle, if that makes sense.

Scenario 2: I have two pairs of points to make the lines, thus four points total -- two points per line. The intersection may be on the line segments, or it may be extended beyond the line segments in either direction.

The lines will never be parallel.

I've spent a few hours researching online and found some possible solutions, by not being very mathematically inclined I get quite lost in all the notation and have had no luck creating an ActionScript translation.

One example that might be what I need:
http://www.faqs.org/faqs/graphics/algorithms-faq/
^ search for "Subject 1.03: How do I find intersections of 2 2D line segments?"

Any help would be greatly appreciate. Thanks!
TOPICS
ActionScript
765
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Dec 24, 2007 Dec 24, 2007
:

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guest
Dec 25, 2007 Dec 25, 2007
Thanks, kglad!

The method using two points per line is working perfectly. Awesome!

However, the angle version is not working for me. Here is the function I'm using to determine angle:
function angle(p1,p2){
return -Math.atan2((p1.x-p2.x), (p1.y-p2.y))/(Math.PI/180);
}

Does that need to be adjusted?
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Dec 25, 2007 Dec 25, 2007
your x and y need to be switched in atan2.
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guest
Dec 25, 2007 Dec 25, 2007
Perfect! Thanks!
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Dec 25, 2007 Dec 25, 2007
you're welcome.
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guest
Dec 30, 2007 Dec 30, 2007
Hey kglad, I'm encountering some behavior I don't understand, wondering if you could shed some light.

I'm using the vector method(pointPointF) and it appears that in the event that a vector is exactly vertical, the intercept returns Infinity or -Infinity. The vectors do intersect, they are not parallel. Horizontal seems to work fine.

Any thoughts would be appreciated. Thanks!
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Dec 30, 2007 Dec 30, 2007
the slope of a vertical line is infinite. so, in the situation where you're trying to find the intersection of a vertical line with any other (non-vertical) line, use the x coordinate of the vertical line and solve for y on your non-vertical line.

eg, if your vertical line is defined by x=3 and your non-vertical line is defined by y=mx+b, the intersection is:

(3,m*3+b);
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guest
Dec 30, 2007 Dec 30, 2007
Excellent, that works. Thanks again!
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Dec 30, 2007 Dec 30, 2007
LATEST
you're welcome.
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines