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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T12:04:19+00:00 2026-06-17T12:04:19+00:00

How can I detect when a 2D moving object has crossed its own path?

  • 0

How can I detect when a 2D moving object has crossed its own path?
enter image description here

I store the path as an array of points based on the plane’s previous positions.

Pseudo-code or any programming language can be used to describe a solution.

Here’s my code I’ve tried already – it detects a full 360 loop. I think I need a different approach.

    CGFloat angleDiff = angleCurr - lastAngleRecorded;
    lastAngleRecorded = angleCurr;

    // Ensure -180 < angleDiff < 180
    angleDiff = angleDiff > M_PI ? angleDiff - (M_PI*2) : angleDiff;
    angleDiff = angleDiff < -M_PI ? angleDiff + (M_PI*2) : angleDiff;

    // Reset tracking of the loop of the plane's angle exceeds (turns too sharply) or falls below the limits

    if(fabsf(angleDiff) < angleDiffMinAllowed || fabsf(angleDiff) > angleDiffMaxAllowed) {
        if(++ringFaultCount >= ringFaultCountMax) {
            [self resetTracking];
            return;
        }
    }

    ringFaultCount = 0;

    // Add plane position to ring polygon
    [ringPoints addObject:[NSValue valueWithCGPoint: ccp(targetPlane.position.x, targetPlane.position.y)]];


    // Add angleDiff to angleTotal
    angleTotal += angleDiff;

    // Completed loop?
    if(fabsf(angleTotal) >= M_PI * 2.f) {

        [self resetTracking];

        if(isRingJoined){
            CCLOG(@"%@ RING COMPLETE", NSStringFromSelector(_cmd));
        }

        return;
    }
  • 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-06-17T12:04:20+00:00Added an answer on June 17, 2026 at 12:04 pm

    I also had the problem, I solved it by making a straight line in a coordinate system:

    y = mx+q±­tolerance
    

    Let me explain:
    The line is the tangent of the curve at the point you check if there is a collision this is the line the “aircraft” followed in that point.
    The tolerance will make the line move a litlle bit up and also one a little bit down.
    so you get 2 parralel lines witch can be seen as boundarys.
    you also have to make a tolerance on the x-axis

    The m is the direction of the line, its: tan(angle), the angle is the angle with the x-axis.

    If all that is setup than you have to do this:

    if(y_point < mx+q+tolerance && y_point> mx+q-tolerance && x_points > x-tolerance && x_point< x+tolerance
    {
    // some code
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

You can detect whether a popup has been blocked in Chrome with the solutions
mouseMove event is for moving on the canvas itself, but I can't detect when
I have a 3d moving box and a stationary box. I can detect collisions
In a WPF application, how can you detect if the mouse pointer has stopped
i know that there are websites which can detect where the mouse is moving
I can detect if my Opera extension installed by setting the new window object
I am doing a project to detect moving object from a moving camera with
I can detect that app is running under iOS Simulator (using sysctlbyname(hw.machine) ), but
I can detect my iPad device running an iPhone app in 1x or 2x
Is there anyway I can detect via jQuery if a select form element is

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.