09-22-2010 09:41 PM
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.
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.
09-22-2010 11:14 PM
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!
09-23-2010 07:29 AM
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
09-23-2010 07:32 PM
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.
09-24-2010 10:24 AM
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.
09-24-2010 12:52 PM
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
09-26-2010 06:29 PM
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.
09-27-2010 03:42 AM
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: