简体   繁体   English

点与线之间的曲线相交

[英]Intersection between curve from points and a line

I'm new in matlab and I'm trying to find the intersection between a curve (from points) and a line. 我是Matlab的新手,正在尝试找到曲线(从点)和直线之间的交点。

I've some points and I've plot the interpolation between this points. 我有一些点,并绘制了这些点之间的插值。 Now I want to find the intersection between the interpolation (xi,yi) curve and another line. 现在,我想找到插值(xi,yi)曲线和另一条线之间的交点。

x = [94.8;84.4;63.1;49.4;40.6;33.8;23.2;20.1;10.2;9.2;7.9];
y = [0; 11.4;29.7;41.6;47.5;50.1;52.9;50.6;32.2;28.1;0];
xi=94.8:-0.1:7.9;
yi=interp1(x,y,xi,'spline');
plot(x,y,'*');
hold on
plot(xi,yi);

I've researched but everything I've found needs a function. 我已经研究过,但发现的所有内容都需要功能。 I already tried to convert the curve to a function using polyfit but the fit is not good enought. 我已经尝试过使用polyfit将曲线转换为函数,但拟合度不够好。

It is posible to do this in matlab? 有可能在matlab中这样做吗?

Thanks. 谢谢。

Basically, the error message ask you to input a function handle (similar to function pointer in other languages). 基本上,错误消息会要求您输入函数句柄(类似于其他语言中的函数指针)。 It's not necessary to convert it into something that matches a mathematical definition of a function (eg polynom): 不必将其转换为与函数的数学定义(例如多项式)相匹配的内容:

f=@(xi)(interp1(x,y,xi,'spline'))

This can be evaluated at every xi. 可以在每个xi处进行评估。

Usage like every other function: 用法与其他函数一样:

f(1)
f(1:3)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM