cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
Showing results for 
Search instead for 
Did you mean: 

How to traverse a curve

SOLVED
Highlighted
Contributor

How to traverse a curve

Dear all,

 

I have a set of close points (every 20 mm for a 100m long curve) which I can import into Mathcad and use linterp to create a temporary function. 

 

But when I need to call the function, I need the input to be the length of the curve. For example,

 

If I have a function y = sin(x) and I need to have a function which calculates the slope (tangent) at a distance 'd' but the distance is measured along the length of the curve sin(x) and not at x=d..

 

Is there any straightforward way of doing this ? I can think of one crude way (slowly start traversing the curve in small increments of x and keep on adding distance between y(x) and y(x+dx) until 'd' is reached and thereby now we know the (x,y) coordinates for the function and go from there). But I have to use this routine thousands of times and I don't think my method is efficient at all. 

Please suggest ?

 

Warm Regards,

Aravind.

 

 

1 ACCEPTED SOLUTION

Accepted Solutions

Re: How to traverse a curve

If you already turned your points into a function (via linterp, splines, or whatever) you may use the integral formula for curve length to do the job.

You are best off if you post a worksheet with your data and your attempts and maybe some concrete numerical examples to show what exactly you are looking for.

As far as I understand you try to derive a parameter representation of a function with curve length as parameter, when a cartesian representation is given.

12 REPLIES 12

Re: How to traverse a curve

If you already turned your points into a function (via linterp, splines, or whatever) you may use the integral formula for curve length to do the job.

You are best off if you post a worksheet with your data and your attempts and maybe some concrete numerical examples to show what exactly you are looking for.

As far as I understand you try to derive a parameter representation of a function with curve length as parameter, when a cartesian representation is given.

Re: How to traverse a curve

Awesome ! I didn't know that there is a simple integral which gives length of curve Smiley Happy      (1 + (dy/dx)^2)^0.5

 

This would work perfectly, except I need to use it in reverse (I know the length and I need to find the x). I think since it's just one equation+variable, given+find block should be fast enough to use in a loop. 

 

Thanks a lot Werner ! 

 

Sorry for not giving any data (Actually I am yet to start making the sheet and was brainstorming ideas on how to achieve my goal and I thought my solution was just too bad so decided to ask for help right away )

Re: How to traverse a curve

Yes , a solve block would give you the inverse you need.

Something like this:

B.png

Depending on the function you use I guess its better not to use a constant guess value but rather make the guess for x dependent on the curve length in some way as shown in the file. But that depends on the function you have. You may give it a try with a constant guess at first.

Mathcad 15 sheet attached.

EDIT: One additional remark. As you are looking for the derivatives I think you should not use linear interpolation but rather spline interpolation for smooth results.

If you stay with linear interpolation, then determining the x-value from a given "curve" length could be programmed easier and exact as it would just mean to determine the length of line segments or parts of them.

Furthermore the "derivative" would be constant between two of your points and not defined at the points themselves (or you may calculate the mean value for them).

BTW, the time consuming part in my approach is not the solve block but rather the numeric derivation.

Re: How to traverse a curve

Thanks a lot Werner !

 

The reason why I use input data as close as possible (20 mm interval for a 100m cable for example), and use linterp is that although it is approx, the slopes are almost correct (I dont use derivative but I use (y2-y1)/(x2-x1) for two points on either side of the given point).

 

I heard that using splines sometimes creates an issue (it sometimes makes ripples between the points (as shown in red) instead of joining them in the sketch below). Since I have closely spaced points in a large cable length, there is no way I can spot these in a graph, but this will grossly affect my results because my results are very sensitive to the calculated slope. 

(please pardon the rough sketch)

 

 

Am I thinking wrong ? 

Re: How to traverse a curve

Hi Werner,

 

Could you please tell me why the attached sheet is not working ?

The solve block is able to find a solution on either sides of a point but is not able to find the solution at that particular point (although it is just part of a straight line since I used linterp function). 

 

Your help is much appreciated !

 

Aravind

Re: How to traverse a curve

A "simple" problem of numerical precision of the integration.

If you decrease TOL to 10^-4 (from the default 10^-3) the problem is solved (at least for this specific input value).

Unfortunately decreasing the values of TOL and CTOL increase the calculation time for the numeric integration.

So if you want to stick to linear interpolation I'd prefer a simpler and more exact solution to get the result by using the fact that we are just dealing with line segments.

But would it make sense to ask for the derivative if you use linear interpolation? It would be constant between two points and what should the derivative be defined at the points where the line segments join?

And why do you think that the value corresponds exactly to one of your points? It doesn't.

The last point corresponds to an input value of approx. 85.100 and the last but one to 19.999.

So all three values corresponds to points somewhere in-midst the last line segment.

B1.png

Re: How to traverse a curve

I agree. 

Could you please give me a hint on how to find the solution faster (instead of using solve block on a finite integral) ? My input curve could be anything (straight line / circular / spline) so I decided to just break them up into a thousand parts and connect them with straight lines. 
This way one approach would work for all types of input (straight lines / circles have equations but for splines I only get a set of points defining the curve).

 

I don't use differentiation to find the slope at any point (like you said, the linterp function is not differentiable at the points where lines meet). Instead I used the old method (f(x+0.001)-f(x-0.001) / 0.002) and I found results to be okay(ish). 

I do face the problem of the sheet running for a whole lot (15 mins or more !) before it can accomplish the purpose and I would really appreciate if you kindly took a glance at it and suggested improvements. The sheet is attached (comments in yellow )

Re: How to traverse a curve

If you can break your input file into small line segments, the attached approach should be quite faster.

Couldn't test is with your new file as the data file (Excel) was missing.

 

Re: How to traverse a curve

Ah sorry.

It is the same data as the one you used. I was trying out different input ways for it and I forgot to input back the coordinates.

 

It's embarrassing a bit but your solution was totally and completely greek and latin to me xD. Could you please explain it at layman's level or point to a source of information ? (In your segments(list) definition, I could understand that you transposed the list matrix, nothing else !)