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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T07:47:08+00:00 2026-05-14T07:47:08+00:00

I have a set of points represented as a 2 row by n column

  • 0

I have a set of points represented as a 2 row by n column matrix.
These points make up a connected boundary or edge. I require a function that traces this contour from a start point P1 and stop at an end point P2. It also needs to be able trace the contour in a clockwise or anti-clockwise direction. I was wondering if this can be achieved by using some of Matlab’s functions.

I have tried to write my own function but this was riddled with bugs and I have also tried using bwtraceboundary and indexing however this has problematic results as the points within the matrix are not in the order that create the contour.

Thank you in advance for any help.

Btw, I have included a link to a plot of the set of points. It is half the outline of a hand.

The function would ideally trace the contour from ether the red star to the green triangle. Returning the points in order of traversal.

EDIT: This is perhaps a work around to a larger problem I am trying to solve but would it be possible to test if a point on the blue boundary edge is connected to the contour that is between either the red stars or green triangular points.

i.e. for a point on the blue boundary, if you were to trace the contour by hand from the left red asterixs to the green triangle the function would return true if the point is on the connected boundary between the two points and false otherwise.

alt text http://img717.imageshack.us/img717/9814/hand1.png

  • 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-14T07:47:09+00:00Added an answer on May 14, 2026 at 7:47 am

    If the points are so close together, you should be able to do the trace by always looking for the next closest point in the list.

    If the point were farther apart, the problem would not be solvable – imagine the five points where four are corners and one is in the center: what is the ‘correct’ way of tracing the line?

    %%# create some points
    npts = 100;
    x = linspace(-1,1,100)'; %'
    y = 1 - x.^2;
    pts = [x,y];
    
    %# shuffle the points
    newOrder = randperm(npts);
    pts = pts(newOrder,:);
    
    %# find index of start, end point
    startIdx = find(newOrder == 1);
    endIdx = find(newOrder == npts);
    
    %# this brings us to where you are - pts as a nx2 array
    %# startIdx indicates the star, and endIdx indicates the triangle.
    
    %# pre-assign output - traceIdx, which contains the ordered indices of the point on the trace
    traceIdx = NaN(npts,1);
    
    %# create distance matrix
    distances = squareform(pdist(pts));
    
    %# eliminate zero-distance along the diagonal, b/c we don't want points linking to themselves
    distances(logical(eye(npts))) = NaN;
    
    %# starting from startIdx: always find the closest next point, store in traceIdx,
    %# check whether we've arrived at the end, and repeat if we haven't
    done = false;
    traceCt = 1;
    traceIdx(1) = startIdx;
    
    while ~done
        %# find the index of the next, closest point
        [dummy,newIdx] = min(distances(traceIdx(traceCt),:));
    
        %# store new index and up the counter
        traceCt = traceCt + 1;
        traceIdx(traceCt) = newIdx;
    
        %# check whether we're done
        if newIdx == endIdx
            done = true;
        else
            %# mask the backward distance so that there's no turning back
            distances(newIdx,traceIdx(traceCt-1)) = NaN;
        end %# if
    end %# while ~done
    
    %# remove NaNs
    traceIdx(~isfinite(traceIdx)) = [];
    
    %# plot result with a line connecting the dots to demonstrate that everything went well.
    figure,
    plot(pts(traceIdx,1),pts(traceIdx,2),'-o')
    hold on,
    plot(pts(startIdx,1),pts(startIdx,2),'*r')
    plot(pts(endIdx,1),pts(endIdx,2),'>g')
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have set of points which lies on the image. These set of points
I have a set of points that i want to turn into a closed
I have a set of X,Y data points (about 10k) that are easy to
Say I have an array that represents a set of points: x = [2,
I have set break points on my attached properties SetXXX and GetXXX static methods.
I have a set S of points (2D : defined by x and y)
I have a set of data points in 3D space which apparently all fall
I have a set of 2D points inside a finite 2D region of space
I have a set of 2D points each with an associated id. (e.g. if
I have a set of transactions occurring at specific points in time: CREATE TABLE

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.