# Can someone help me calculate curves

## My MATLAB forum

﻿

### Calculate the distance between two curves

 Posted: 17.04.2013, 11:22     title:
 Hello Jan, of course I mean linear interpolation. I imported the data as "Column vectors" (from Excel), i.e. 4 individual columns. Your solution is already not bad and I try to implement it, but it only brings me one means, a maximum deviation would be important to me. @Winkow I got there >> plotyy (Latgps, Longps, latmaps, lonmaps); figure (gcf); To get in touch, I started with a short script introducing Matlab. Otherwise I only used the search to see if there was already a similar problem. As I said, I have no idea about Matlab, I only need (hopefully) this one evaluation.

 Posted: 06.05.2013, 14:38     title:
 Hello, I can't get any further with my problem and (unfortunately) just don't get to familiarize myself with the matter because other parts of my work are more important. Maybe someone can help me little by little. Again briefly, what do I have: 4 vectors (x1, y1, x2, y2) The vectors x1 and y1 each contain <79924x1 double> data points, x2 and y2 each <39859x1 double>. *** Theoretically, I imagine my evaluation as follows: I would like to run straight lines through my 79924 points, i.e. always from point to point. I get the straight line from two given points [P (x11 / y11) Q (x12 / y12)] => My straight line g: x = p + r * (q-p) So next the perpendicular (i.e. slope of the straight line * (- 1)) should be intersected with ONE point of the vectors (x2, y2). Apart from the fact that I already can't program the straight lines (and have already looked for a wolf here), but maybe a buddy can help me, I now see the biggest problem, because now Matlab should use the closest point ( x2 and y2), cut with the solder and "spit out" the distance. Then the next straight line through Q and R etc ... Maybe someone is bored ... I tried Jan's solution and got a result, but the result is not meaningful for me because I don't know whether there are overlapping areas and the maximum distance is important to me, unfortunately the means does not help me Thank you in advance for reading through *** alternatively I also have 2 matrices A and B, which then contain the same data, then each have x1 and y1, or 2, in the columns next to each other. P.S. I hope I haven't messed up too much and my problem is understandable.

 Posted: 06.05.2013, 16:37     title:
 Hello Funkyspike, What kind of help do you envision? It's your thesis. Is it then okay if you let someone else write a program for it and of course you explain this in your work under "Aids"? Or does your supervisor expect you to solve this yourself? In the first case, the heading "Programming jobs" could also be helpful. In any case, the problem is clearly described. It's actually not difficult to implement. The equations of the perpendicular and the formula for the distance between points and straight lines are elementary vector calculations. Maybe you still have your old exercise books at hand. But Wikipedia also knows the formulas. Then another FOR loop over all points - an inefficient implementation might take a few minutes longer, but that shouldn't be the problem, right? I always prefer to help when the questioners at least post approaches in Matlab. Greetings, Jan

 Posted: 07.05.2013, 10:00     title:
 Jan S wrote the following: Hello Funkyspike, What kind of help do you envision? It's your thesis. Is it then okay if you let someone else write a program for it and of course you explain this in your work under "Aids"? Or does your supervisor expect you to solve this yourself? In the first case, the heading "Programming jobs" could also be helpful.

Hello Jan, in the worst case the former case, of course I would like to do it myself, but I've never had anything to do with Matlab.
My supervisor only wants one result, he advised me to look for finished scripts "there is sure to be something ..." - Great, thank you!

 Jan S wrote the following: In any case, the problem is clearly described. It's actually not difficult to implement. The equations of the perpendicular and the formula for the distance between points and straight lines are elementary vector calculations. Maybe you still have your old exercise books at hand. But Wikipedia also knows the formulas. Then a FOR loop over all points - an inefficient implementation might take a few minutes longer, but that shouldn't be the problem, right?

I could solve the problem by hand, that would not be a problem (well, the scope, that's why Matlab), I can still reasonably know the mathematical basics, which is the simplest upper-level mathematics.
But I don't have any basics of Matlab programming, so I don't know how to access my data correctly.

Help to get started might not be bad.

I have stored the data (short excerpt) for curve A as follows:
A] ___ 1_______2___
A1] 49.0188 8.4371
A2] 49.0187 8.4372
A3] 49.0186 8.4373
A4] 49.0185 8.4374

And now I don't know how to proceed in Matlab, because I only have approaches for 3 points, for example, which are individually saved as P, Q, R, but not as shown above.

y1 = (A2) + r * (A2-A1)
y2 = (A3) + r * (A3-A2) etc ...

Maybe someone can solve this "problem" for me / write that I have an approach and then try further ...

Thanks!

 Posted: 07.05.2013, 11:49     title:
 Hello, yes, the curves are closed. I've already tried your approach (probably more complicated, or too easy !?) BUT, as already written above, I only get the average distance, but it doesn't help me. Especially when the surfaces overlap, the mean is not right either. The maximum distance is important to me. But I think I've just learned a little something new. "y1 = x. ^ 2" is this "." what makes me difficult above? Is it now going through one point at a time? I'm trying to keep tinkering with my approach. Thank you in any case!!

 Posted: 07.05.2013, 14:24     title:
I'm trying little by little now.

 Funkyspike wrote the following: what do I have: 2 matrices A and B A: 79924 lines; 2 columns B: 39859 lines; 2 columns. I would like to run straight lines through my 79924 points, i.e. always from point to point.

Well what did I do now, I tried to set up a straight line equation:

but there it starts again that "r" is not defined, furthermore I would like to let it run through automatically, because I can't set up all 79924 straight lines, well, I can ...

As a result, I would like Matlab to spit out the straight line equation so that I can form the normal.

g1 = (x21 / y21) + r * ((x21-x11) / (y21-y11))

(to simplify the writing a = (x21-x11), b = (y21-y11)).

For the normal vector, instead of (a / b) -> (-b / a), so is

n1 = (x21 / y21) + r * (- b / a) my normal vector.
n2 then just as with (-c / b) etc ...

But how on earth do I write this in Matlab?

 Posted: 10.05.2013, 10:41     title:
so, I sat down with my supervisor and we tinkered something together.
now I already have a basic framework, but for now I still have a little something. I would like to save all 78 intermediate results, both the distance and the intersection points. How does it work?
I've already tried something with "end + 1", but I didn't get it.
 Code:% This is our program.for i = 1: 79     Calculate% gradient m = (A ((i + 1), 2) - A (i, 2)) / (A ((i + 1), 1) - A (i, 1)); Calculate% Y-axis intercept n = (A (i, 2) - m * A (i, 1)); % Normal slope m_lot = -1 / m; % Normal Y-axis section n_lot = (B (i, 2) - m_lot * B (i, 1)); % Intersection of line g and perpendicular through point B% define the variable xsyms x % X value for intersection x_schnitt = solve ('(m * x + n) = (m_lot * x + n_lot)'); x_SP = subs (x_section); % Y value for intersection y_section = g (x_SP, m, n); y_SP = subs (y_section); % shortest distance from point to straight line distance = sqrt ((y_section - B (i, 2)) ^ 2 + (x_section - B (i, 1)) ^ 2); % Intersection cut = [x_SP y_SP]; end