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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T23:23:32+00:00 2026-05-25T23:23:32+00:00

I need to write a small program which to test whether a line (position

  • 0

I need to write a small program which to test whether a line (position vector) does strictly clockwise or CCLW movement. I tried to use atand to find the angle, but it could jump from negative to positive value when it pass thought 90 deg, it will have the same thing if I use slope method.

However, the motion does not have to cut at 90 deg, it could jump from 89 to 91. Then a big slope jump could happen. Any idea please

Thanks

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

    One way to do this would be to calculate the cross-product of consecutive position vectors. If all the cross-products are positive then the line moved with a strictly clockwise. Similarly, if they are all negative then the line moved counter-clockwise. If the signs are mixed then the line did not move strictly in one angular direction:

    function checkRotation(pos)
    
    pos(:,3) = 0;
    pos = unique(sum(sign(cross(pos(1:end-1,:), pos(2:end,:))), 2));
    if isequal(pos, 1)
        disp('Rotation was counter-clockwise');
    elseif isequal(pos, -1)
        disp('Rotation was clockwise');
    else
        disp('No strict rotation direction');
    end
    

    Create some random position vectors on -10<=x<=10 and -10<=y<=10 and test rotation:

    >> pos = 20 * rand([10, 2]) - 10
    
    pos =
    
             -8.28968405819912          9.26177078573826
             -4.75035530603335         0.936114374779359
              6.02029245539477         0.422716616080031
             -9.41559444875707         -5.36811226582952
              8.57708278956089        -0.222045121596661
              4.60661725710906          2.48120176347379
            -0.227820523928417          3.58271081731495
              1.57050122046878         -2.08969568662814
             -5.25432840456957         -2.65126702911047
            -0.823023436401378          9.75964006323266
    
    >> checkRotation(pos)
    No strict rotation direction
    

    Create position vectors that move only CCW and test:

    >> theta = 0:15:180;
    >> pos = [cosd(theta)' sind(theta)'];
    >> checkRotation(pos)
    Rotation was counter-clockwise
    

    and similarly for CW rotation:

    >> theta = 180:-15:0;
    >> pos = [cosd(theta)' sind(theta)'];
    >> checkRotation(pos)
    Rotation was clockwise
    

    Note that the success of rotation detection is limited by your sampling rate. If the line rotates counter-clockwise by more than 180 degrees in successive samplings of the line position, it is indistinguishable from a rotation less than 180 degrees in the clockwise direction. This is an example of aliasing.

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

Sidebar

Related Questions

I need to write a small program that can detect that it has been
As the title says, I need to write a small program to read data
I'm looking to write a small program which will intercept network packets (on the
I need to write a small program for the university. The problem is, it
I have to write a program in which main calls other functions that test
In my project I need to write small WYSIWYG editor (just let users make
I need to write a small console app (patch) that turns off the print
I need write an update statement that used multiple tables to determine which rows
I need to write a program used internally where different users will have different
I would like to write a small piece of program that launches threads, consumes

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.