Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Thread Subject:
distance control

Subject: distance control

From: Nora

Date: 24 Aug, 2010 23:11:04

Message: 1 of 6

Hi,
I have a set of datapoints(x,y) which lie on a contour line and I have a distance from the starting point. And I have to determine the last coordinates of this distance which intersect somewhere on this datapoints.
Could anyone give me a suggestion about how can I achieve this?
Thanks in advance

Subject: distance control

From: Darren Rowland

Date: 25 Aug, 2010 01:46:06

Message: 2 of 6

Could you rephrase the question please?
And perhaps provide some sample data.

Subject: distance control

From: ImageAnalyst

Date: 25 Aug, 2010 02:21:33

Message: 3 of 6

I second that. I've read it 7 or 8 times and I still have no idea
what you want. A distance is a length. How can it have coordinates
or intersect anything? The two endpoints of a line segment can each
have an (x,y) coordinate, but a distance can't. A line segment can
intersect a curve or contour, but a distance can't - it doesn't make
sense. And what is the "last coordinates"? Do you mean the
coordinates of ONE of the endpoints of a line segment that is a
certain distance long? Does your intersection coordinate need to be
already in your datapoints() collection, or can the intersection be a
point that needs to be interpolated in between the existing datapoints
points?

Subject: distance control

From: Nora

Date: 25 Aug, 2010 21:09:20

Message: 4 of 6

ImageAnalyst <imageanalyst@mailinator.com> wrote in message <e2a38f77-0057-4cb9-9659-99fccc38490a@v41g2000yqv.googlegroups.com>...
> I second that. I've read it 7 or 8 times and I still have no idea
> what you want. A distance is a length. How can it have coordinates
> or intersect anything? The two endpoints of a line segment can each
> have an (x,y) coordinate, but a distance can't. A line segment can
> intersect a curve or contour, but a distance can't - it doesn't make
> sense. And what is the "last coordinates"? Do you mean the
> coordinates of ONE of the endpoints of a line segment that is a
> certain distance long? Does your intersection coordinate need to be
> already in your datapoints() collection, or can the intersection be a
> point that needs to be interpolated in between the existing datapoints
> points?

ImageAnalyst, Many thanks for your reply.
I plot contour map with my dataset and then took the coordinates of these contour levels by contourc command and obtained levels of contours and number of data points belong to these level and coordinates of the data points which create the contour lines. Also, I have a length value (such as 288.45 m). I try to find the coordinate of this length along this contour.

Level1 Number1
x1 y1
x2 y2 ==>S1=((x1-x2)^2+(y1-y2)^2)^0.5
x3 y3 ==>S2=...
.. ..
S1+S2+S3+...+S=288.45
S=((x-xn)^2+(y-yn)^2)^0.5
x,y is the result.
But, I didnt achieve to make it in a loop. My contour line number changes every time, (I know priorly the length values for each contour line) and I am not good at coding.
Hope this time clear.

Subject: distance control

From: Roger Stafford

Date: 26 Aug, 2010 00:12:05

Message: 5 of 6

"Nora " <nursutun@yahoo.com> wrote in message <i540q0$c8v$1@fred.mathworks.com>...
> I plot contour map with my dataset and then took the coordinates of these contour levels by contourc command and obtained levels of contours and number of data points belong to these level and coordinates of the data points which create the contour lines. Also, I have a length value (such as 288.45 m). I try to find the coordinate of this length along this contour.
>
> Level1 Number1
> x1 y1
> x2 y2 ==>S1=((x1-x2)^2+(y1-y2)^2)^0.5
> x3 y3 ==>S2=...
> .. ..
> S1+S2+S3+...+S=288.45
> S=((x-xn)^2+(y-yn)^2)^0.5
> x,y is the result.
> But, I didnt achieve to make it in a loop. My contour line number changes every time, (I know priorly the length values for each contour line) and I am not good at coding.
> Hope this time clear.
- - - - - - - - - -
  At last I think I can understand what you are asking, Nora! You want to follow a contour along its line segments a given total chord-line distance from one of the ends. Is that right?

  The following code is just for one contour. You will have to rewrite it to accommodate a number of contours. Let X be a row vector of the x-coordinates along the contour and Y a row vector of the y-coordinates. Let 'dist' be the distance (288.45 in your example) you wish to go along the contour from the start point.

 dX = diff(X); dY = diff(Y);
 s = sqrt(dX.^2+dY.^2); % The lengths of the segments
 c = [0,cumsum(s)]; % Cumulative lengths
 p = find(diff(c>dist)==1); % Find which segment will have (x,y) in it
 if isempty(p) % The quantity 'dist' is too long for the contour
  error('The contour is not that long.')
 else % We have found the segment for (x,y)
  t = (dist-c(p))/s(p); % Compute the fraction of the way along the segment
  x = X(p)*(1-t) + X(p+1)*t; % Find where (x,y) is in the segment
  y = Y(p)*(1-t) + Y(p+1)*t;
 end

The point (x,y) is at the required total distance along the contour.

Roger Stafford

Subject: distance control

From: TideMan

Date: 26 Aug, 2010 00:54:50

Message: 6 of 6

On Aug 26, 12:12 pm, "Roger Stafford"
<ellieandrogerxy...@mindspring.com.invalid> wrote:
> "Nora " <nursu...@yahoo.com> wrote in message <i540q0$c8...@fred.mathworks.com>...
> > I plot contour map with my dataset and then took the coordinates of these contour levels by contourc command and obtained levels of contours and number of data points belong to these level and coordinates of the data points which create the contour lines. Also, I have a length value (such as 288.45 m). I try to find the coordinate of this length along this contour.
>
> > Level1 Number1
> > x1 y1
> > x2 y2  ==>S1=((x1-x2)^2+(y1-y2)^2)^0.5
> > x3 y3  ==>S2=...
> > ..  ..
> > S1+S2+S3+...+S=288.45
> > S=((x-xn)^2+(y-yn)^2)^0.5
> > x,y is the result.
> > But, I didnt achieve to make it in a loop. My contour line number changes every time, (I know priorly the length values for each contour line) and I am not good at coding.
> > Hope this time clear.
>
> - - - - - - - - - -
>   At last I think I can understand what you are asking, Nora!  You want to follow a contour along its line segments a given total chord-line distance from one of the ends.  Is that right?
>
>   The following code is just for one contour.  You will have to rewrite it to accommodate a number of contours.  Let X be a row vector of the x-coordinates along the contour and Y a row vector of the y-coordinates.  Let 'dist' be the distance (288.45 in your example) you wish to go along the contour from the start point.
>
>  dX = diff(X); dY = diff(Y);
>  s = sqrt(dX.^2+dY.^2); % The lengths of the segments
>  c = [0,cumsum(s)]; % Cumulative lengths
>  p = find(diff(c>dist)==1); % Find which segment will have (x,y) in it
>  if isempty(p)  % The quantity 'dist' is too long for the contour
>   error('The contour is not that long.')
>  else % We have found the segment for (x,y)
>   t = (dist-c(p))/s(p); % Compute the fraction of the way along the segment
>   x = X(p)*(1-t) + X(p+1)*t; % Find where (x,y) is in the segment
>   y = Y(p)*(1-t) + Y(p+1)*t;
>  end
>
> The point (x,y) is at the required total distance along the contour.
>
> Roger Stafford

Alternatively, once you've calculated c as Roger showed:
x=interp1(c,X,dist);
y=interp1(c,Y,dist);
Note: if dist is outside c, x and y will be NaN.

Tags for this Thread

No tags are associated with this thread.

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Contact us