LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

intersection of line and curve

I want the opinion of others as to the best way to approach this situation.

 

I have a curve defined by (x,y1), and also a straight line y2 = constant. In the example below, y2 = 2.

 

I want to find the intersection of the curve with the line.

 

 

 

 

24536i07E3750F0BF274DF

 

 

 

My apporach is as follow:

 

1. Find the polynomial coefficients of the curve(x,y1) using general polynomial fit

 

2. subract (y2 = 2) from  the first polynomial coeficient i.e solving y1 = y2

 

3. Solve the equation of the polynomial equation using polynomial roots

 

 

I want to see if there are other ideas.

 

Thanks.

 

0 Kudos
Message 1 of 8
(7,065 Views)

This is a good general approach, from a "formal" point of view.

I would personally choose another solution.

You can scan the Y1 array in a for loop looking for a couple of successive values which satisfy the following inequality:

 

Y1[i] < Y2[i] < Y1[i+1];

 

then, for each couple, simply interpolate the two Y1 values to find the correspondent X (index of Y2 array).

 

Have fun!

 

Message 2 of 8
(7,057 Views)

The Threshold 1D Array function (array palette) will find the fractional index (interpolated) where the Y values cross the threshold.  This works only for increasing values so you might need to reverse the array and repeat to find both intersections.  If the curve can cross the threshold several times, it might be necessary to break the Y-array into segments.  After you find the indexes of the Y-array, you can determine the values of X from the X-array.

 

This will only work if the X-array values are uniformly spaced as in your example.

 

Lynn

Message 3 of 8
(7,032 Views)

Try and look at my example which shows what I mean.

It's been compiled for LV 2009.

Let me know if you need a previous version.

 

B.

Message 4 of 8
(7,003 Views)

Beautiful code. Thank you Blueyes.

 

However, my curve in practice has just few points ( like 20), and is erratic. What I have decided to do is combine my method with yours.

 

1. I will solve for the equation using a polynomial order of about 12(this gives a very good fit)

2. subtract the constant value(y2) from the first polynomial coefficient

3. solve the polynomial equation (roots)

4. Since I will get many solution, I will now use your code to decipher which roots are valid.

 

Once again, thanks for your input.

0 Kudos
Message 5 of 8
(6,972 Views)

Blueyes,

 

Your code misses one of the two intersections. The Insert into Array overwrites the first intersection with the second one.  Build Array is a better choice.  If the number of intersections could be large, pre-initializing the array and using Replace Array Subset is the best choice.

 

You can simplify things a bit by using autoindexing.  No need for the Array length.  Use of a shift register eliminates the Y1 Index Array and autoindexing eliminates the X Index Array. Wiring Y2 constant value directly to the In Range and Coerce functions eliminated the need to index the Y2 array, which is only needed for the plot.

 

If the Y1 array has noise or horizontal sections, other techniques may need to be used.

 

Lynn

Message 6 of 8
(6,950 Views)

I like the most of your changes, Lynn but it's not true that "the Insert into Array overwrites the first intersection with the second one".

The problem was actually I forgot to include one of the two limits in the "In Range and Coerce" VI. If you don't do it, the algorithm won't work for every "Y2 constant value".

Look at the new VI and try now.

The other suggestions are good.

 

B.

Message 7 of 8
(6,899 Views)

If the data is well described by a polynomial, there is no reason not to use the built-in tools. Here's a quick example:

 

 

Message 8 of 8
(6,888 Views)