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 663533
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T23:30:00+00:00 2026-05-13T23:30:00+00:00

This is a lot more complicated than it might seem at first. What I

  • 0

This is a lot more complicated than it might seem at first. What I have is a giant array which consists of more arrays which contain points [in the form of an array “x,y”] like so:

Array (
    [0] => Array (
        [0] => "0,9",
        [1] => "0,0",
        [2] => "9,0",
        [3] => "9,9",
        [4] => "0,9"
        )
    [1] => Array (
        [0] => "1,5",
        [1] => "1,6",
        [2] => "3,6",
        [3] => "3,8",
        [4] => "4,8"
    )
    ... and so on ...
)

So what I need to do is process through all the points and see if any point in an array, say $points[0][1] to $points[0][2], intersects with any other line segment that could exist in the array. All the line segments are consecutive following the order they are in within each of their respective arrays. So in the first array, “0,9” goes to “0,0” and no other point in that array. The last point in an array does not loop back around to the first point in an array. Also, it should not be considered an intersection if a line segment ends at the intersection of another line segment, it actually needs to cross the line segment it intersects.

I was thinking of plotting the segments as I processed them. So like run through the arrays plotting each point on a ‘virtual’ grid per say and then each array after that would calculate if it intersects another segment which is already plotted, if that makes any sense, but that still seems like it might take a while to calculate if there are a lot of line segments in the array. It seems like what I’d be doing is for each segment in an array, calculate if it intersects any segments previous to it (because theoretically it could intersect a segment in the same array it is in). There has got to be a simpler way to do this, right?

P.S. I couldn’t really think of what tags this should fall under other than PHP. If you think of any please feel free to retag it.

  • 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-13T23:30:00+00:00Added an answer on May 13, 2026 at 11:30 pm

    Here’s a simple method which would be acceptable if the number of points in each list is small:

    1. Take the first two line segments in your array and check if they intersect.
    2. If not, check the next line segment against the previous line segments
    3. Continue till the last point and reiterate for another array (I’m assuming this check you’re doing is for each sub array).

    This is O(n2) where n is the number of points in all your subarrays — if n is small – awesome, if not, let us know.

    Update: If O(n2) is not good enough …

    Sweep line algorithm for segment intersection – supposedly O(n log (n))

    Input: A set of line segments in the plane.

    Output: The set of intersection points among the segments in S.

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

Sidebar

Related Questions

I have a construction similar to this (but a lot more complicated): var list
This is more of a maths question than programming but I figure a lot
It sounds a lot more complicated than it really is. So in Perl, you
Imagine this case, but with a lot more component buckets and a lot more
use this website a lot but first time posting. My program creates a number
I have seen this in a lot of XML comments for classes in the
I have a complicated algorithm that updates 3 histograms that are stored in arrays.
I have an extremely complicated relational database, which is causing me to use the
I see stuff like this a lot: interface A { ... } interface B
I find myself writing code that looks like this a lot: set<int> affected_items; while

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.