Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 614649
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T18:08:04+00:00 2026-05-13T18:08:04+00:00

Lets say we have 4 Vector2 ‘s (yes this is 2d), so we have

  • 0

Lets say we have 4 Vector2‘s (yes this is 2d), so we have lineOneStart, lineOneEnd, lineTwoStart and lineTwoEnd.

How can I detect if the 2 lines cross? I don’t care where they cross, I just want to know if they intersect.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-13T18:08:04+00:00Added an answer on May 13, 2026 at 6:08 pm

    Check this formula by Bourke.

    I recently had to solve this issue too. Another option is using (getting) the equation of the line (y = mx + c) but there are several edge cases you need to be concerned with, as well as actually checking if the point of intersection is within the line segment. The formula in the link above works, though I cannot really comment on how the equation is re-arranged, all I’ll say is it works 😉

    Edit:

    As mentioned by AndiDog, another site I used (the example is excellent too) is this tutorial. As this is XNA the second link will be right up your street.

    Edit (Content from broken link):

    The equations of the lines are Pa = P1 + ua ( P2 - P1 ) and Pb = P3 + ub ( P4 - P3 )

    Solving for the point where Pa = Pb gives the following two equations in two unknowns (ua and ub)
    x1 + ua (x2 - x1) = x3 + ub (x4 - x3)
    and
    y1 + ua (y2 - y1) = y3 + ub (y4 - y3)
    Solving gives the following expressions for ua and ub

    Substituting either of these into the corresponding equation for the line gives the intersection point. For example the intersection point (x,y) is
    x = x1 + ua (x2 - x1)
    y = y1 + ua (y2 - y1)

    Notes:
    The denominators for the equations for ua and ub are the same.
    If the denominator for the equations for ua and ub is 0 then the two lines are parallel.
    If the denominator and numerator for the equations for ua and ub are 0 then the two lines are coincident.
    The equations apply to lines, if the intersection of line segments is required then it is only necessary to test if ua and ub lie between 0 and 1. Whichever one lies within that range then the corresponding line segment contains the intersection point. If both lie within the range of 0 to 1 then the intersection point is within both line segments.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Lets say have this immutable record type: public class Record { public Record(int x,
Lets Say i have a table like this WEB_LIST_TABLE KEY Value ---------------------------------------- 134 google.com
I have this piece of code: while(fileStream>>help) { MyVector.push_back(help); } ...and lets say that
Is there any way that you can combine predicates? Lets say I have something
Lets say I have these lines of code; std::vector<int> ints; std::for_each(ints.begin(), ints.end(), [](int& val){
Lets say I have 2 points (x1,y1) and (x2,y2). And I can draw vector
Lets say you have this: P1 = (x=2, y=50) P2 = (x=9, y=40) P3
Lets say that I have got a vector like this. std::vector<a_complicated_whatever_identifier *> *something =
Lets say if I have a vector V, which has 10 elements. If I
Lets say we have a table here, populated with the following data: acc_id1 acc_id2

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.