【源码】快速而稳健的两条曲线交点计算

在这里插入图片描述

此函数计算两条曲线相交的(x,y)位置。

This function computes the (x,y) locations where two curves intersect.

曲线可以用NaN断开或具有垂直分段。

The curves can be broken with NaNs or have vertical segments.

该函数的运算也非常快(至少我认为在典型应用程序的数据处理上是很快的)。

It is also very fast (at least on data that represents what I think is a typical application).

部分代码如下:

function [x0,y0,iout,jout] = intersections(x1,y1,x2,y2,robust)

%INTERSECTIONS Intersections of curves.

% Computes the (x,y) locations where two curves intersect. The curves

% can be broken with NaNs or have vertical segments.

%

% Example:

% [X0,Y0] = intersections(X1,Y1,X2,Y2,ROBUST);

%

% where X1 and Y1 are equal-length vectors of at least two points and

% represent curve 1. Similarly, X2 and Y2 represent curve 2.

% X0 and Y0 are column vectors containing the points at which the two

% curves intersect.

%

% ROBUST (optional) set to 1 or true means to use a slight variation of the

% algorithm that might return duplicates of some intersection points, and

% then remove those duplicates. The default is true, but since the

% algorithm is slightly slower you can set it to false if you know that

% your curves don’t intersect at any segment boundaries. Also, the robust

% version properly handles parallel and overlapping segments.

%

% The algorithm can return two additional vectors that indicate which

% segment pairs contain intersections and where they are:

%

% [X0,Y0,I,J] = intersections(X1,Y1,X2,Y2,ROBUST);

%

% For each element of the vector I, I(k) = (segment number of (X1,Y1)) +

% (how far along this segment the intersection is). For example, if I(k) =

% 45.25 then the intersection lies a quarter of the way between the line

% segment connecting (X1(45),Y1(45)) and (X1(46),Y1(46)). Similarly for

% the vector J and the segments in (X2,Y2).

%

% You can also get intersections of a curve with itself. Simply pass in

% only one curve, i.e.,

%

% [X0,Y0] = intersections(X1,Y1,ROBUST);

%

% where, as before, ROBUST is optional.

% Version: 2.0, 25 May 2017

% Author: Douglas M. Schwarz

% Email: dmschwarz=ieeeorg, dmschwarz=urgradrochester*edu

% Real_email = regexprep(Email,{’=’,’*’},{’@’,’.’})

% Theory of operation:

%

% Given two line segments, L1 and L2,

%

% L1 endpoints: (x1(1),y1(1)) and (x1(2),y1(2))

% L2 endpoints: (x2(1),y2(1)) and (x2(2),y2(2))

%

% we can write four equations with four unknowns and then solve them. The

% four unknowns are t1, t2, x0 and y0, where (x0,y0) is the intersection of

% L1 and L2, t1 is the distance from the starting point of L1 to the

% intersection relative to the length of L1 and t2 is the distance from the

% starting point of L2 to the intersection relative to the length of L2.

%

% So, the four equations are

%

% (x1(2) - x1(1))*t1 = x0 - x1(1)

% (x2(2) - x2(1))*t2 = x0 - x2(1)

% (y1(2) - y1(1))*t1 = y0 - y1(1)

% (y2(2) - y2(1))*t2 = y0 - y2(1)

%

% Rearranging and writing in matrix form,

%

% [x1(2)-x1(1) 0 -1 0; [t1; [-x1(1);

% 0 x2(2)-x2(1) -1 0; * t2; = -x2(1);

% y1(2)-y1(1) 0 0 -1; x0; -y1(1);

% 0 y2(2)-y2(1) 0 -1] y0] -y2(1)]

%

% Let’s call that A*T = B. We can solve for T with T = A\B.

%

% Once we have our solution we just have to look at t1 and t2 to determine

% whether L1 and L2 intersect. If 0 <= t1 < 1 and 0 <= t2 < 1 then the two

% line segments cross and we can include (x0,y0) in the output.

%

% In principle, we have to perform this computation on every pair of line

% segments in the input data. This can be quite a large number of pairs so

% we will reduce it by doing a simple preliminary check to eliminate line

% segment pairs that could not possibly cross. The check is to look at the

% smallest enclosing rectangles (with sides parallel to the axes) for each

% line segment pair and see if they overlap. If they do then we have to

% compute t1 and t2 (via the A\B computation) to see if the line segments

% cross, but if they don’t then the line segments cannot cross. In a

% typical application, this technique will eliminate most of the potential

% line segment pairs.

% Input checks.

if verLessThan(‘matlab’,‘7.13’)

error(nargchk(2,5,nargin)) %#ok<NCHKN>

else

narginchk(2,5)

end

源码下载地址:

http://page2.dfpan.com/fs/6lcaj2021729416d2b4/

更多精彩文章请关注微信号:在这里插入图片描述

  • 1
    点赞
  • 6
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
内存画板,在内存中创建一个画板并画图。 2.0版本相比于旧版本,增加了画板添加路径,路径或区域转换为剪裁区,剪裁区的基本操作,结合剪裁区的应用可以画出更多图形。 如果画弦、饼、圆弧、弧线之后,可以获取弧线个端点的坐标。 2.2版本公开了:类&ldquo;图片对象&rdquo;和子程序&ldquo;_计算线角度()、_计算线的终点()&rdquo; _计算线的终点() 需要提供{起点,长度,角度},计算出终点,可以当做计算圆上某一点{圆心,半径,角度} 新增:ICO图标类和子程序&ldquo;_计算点间的距离()、_计算两条线交点()&rdquo; 内存画板增加&ldquo;画圆弧路径文字()&rdquo;,可以画出按照圆弧排列的文字 2.5版本新增类&ldquo;动态矢量画板&rdquo;,画出的图形可以随着鼠标滚轮滚动放大缩小 画出的形状支持半透明颜色(画笔颜色、**颜色、文本颜色为ARGB颜色) 3.0版本新增子程序:_计算点到线段的最短距离()、_计算点到直线的垂点距离()、_计算椭圆上的一点()、置窗口透明度_()。 类&ldquo;动态矢量画板&rdquo;增加更多的命令,可设置Y轴正方向是向上还是向下。 新增类&ldquo;图片窗口类&rdquo;,可在&ldquo;图片窗口示例.e&rdquo;预览效果。 附送一个(源码分享)用内存画板为主体创建的表格类。 3.3版本新增子程序:计算贝塞尔曲线控制点()、计算贝塞尔曲线控制点_X() 只需要提供贝塞尔曲线的顶点,可计算曲线的控制点,直接用计算结果的数组画贝塞尔曲线即可 修复部分bug。 点此查看其它版本
<项目介绍> 该资源内项目源码是个人的毕设,代码都测试ok,都是运行成功后才上传资源,答辩评审平均分达到94.5分,放心下载使用! 该资源适合计算机相关专业(如人工智能、通信工程、自动化、软件工程等)的在校学生、老师或者企业员工下载,适合小白学习或者实际项目借鉴参考! 当然也可作为毕业设计、课程设计、课程作业、项目初期立项演示等。如果基础还行,可以在此代码基础之上做改动以实现更多功能。 双目测距理论及其python运用 一、双目测距基本流程 Stereo Vision, 也叫双目立体视觉,它的研究可以帮助我们更好的理解人类的双眼是如何进行深度感知的。双目视觉在许多领域得到了应用,例如城市三维重建、3D模型构建(如kinect fusion)、视角合成、3D跟踪、机器人导航(自动驾驶)、人类运动捕捉(Microsoft Kinect)等等。双目测距也属于双目立体视觉的一个应用领域,双目测距的基本原理主要是三角测量原理,即通过视差来判定物体的远近。 那么总结起来,双目测距的大致流程就是: **双目标定 --> 立体校正(含消除畸变) --> 立体匹配 --> 视差计算 --> 深度计算(3D坐标)计算** linux下安装opencv-python: ```python pip install opencv-python ``` 二、相机畸变 光线经过相机的光学系统往往不能按照理想的情况投射到传感器上,也就是会产生所谓的畸变。畸变有种情况:一种是由透镜形状引起的畸变称之为径向畸变。在针孔模型中,一条直线投影到像素平面上还是一条直线。可是,在实际拍摄的照片中,摄像机的透镜往往使得真实环境中的一条直线在图片中变成了曲线。越靠近图像的边缘,这种现象越明显。由于实际加工制作的透镜往往是中心对称的,这使得不规则的畸变通常径向对称。它们主要分为大类,桶形畸变 和 枕形畸变(摘自《SLAM十四讲》)如图所示: <div align=center><img src=&quot;https://img-blog.csdnimg.cn/20190907184815326.PNG&quot; width=&quot;324&quot; height=&quot;100&quot; /></div> 桶形畸变是由于图像放大率随着离光轴的距离增加而减小,而枕形畸变却恰好相反。 在这种畸变中,穿过图像中心和光轴有交点的直线还能保持形状不变。
在Delphi中使用TChart动态显示多条曲线源码可以如下所示: ```delphi unit Unit1; interface uses Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics, Vcl.Controls, Vcl.Forms, Vcl.Dialogs, VCLTee.Series, Vcl.ExtCtrls, VCLTee.TeEngine, VCLTee.TeeProcs, VCLTee.Chart; type TForm1 = class(TForm) Chart1: TChart; Timer1: TTimer; procedure FormCreate(Sender: TObject); procedure Timer1Timer(Sender: TObject); private { Private declarations } procedure AddRandomData(Series: TLineSeries); public { Public declarations } end; var Form1: TForm1; implementation {$R *.dfm} procedure TForm1.FormCreate(Sender: TObject); var Series1, Series2: TLineSeries; begin // 创建两条曲线 Series1 := TLineSeries.Create(Chart1); Series2 := TLineSeries.Create(Chart1); // 设置曲线的标题和样式 Series1.Title := '曲线1'; Series2.Title := '曲线2'; Series1.Pointer.Visible := True; Series2.Pointer.Visible := True; // 将曲线添加到图表中 Chart1.AddSeries(Series1); Chart1.AddSeries(Series2); // 设置图表的标题和坐标轴名称 Chart1.Title.Text.Text := '动态显示多条曲线'; Chart1.BottomAxis.Title.Caption := 'X轴'; Chart1.LeftAxis.Title.Caption := 'Y轴'; // 启动定时器,定时刷新曲线数据 Timer1.Enabled := True; end; procedure TForm1.Timer1Timer(Sender: TObject); begin // 每个定时周期更新曲线的数据 AddRandomData(TLineSeries(Chart1.Series[0])); AddRandomData(TLineSeries(Chart1.Series[1])); end; procedure TForm1.AddRandomData(Series: TLineSeries); begin // 随机生成曲线的数据点 Series.Add(Random(100), Random(100)); // 更新图表显示 Chart1.AutoRepaint := True; end; end. ``` 这是一个简单的示例,其中通过TLineSeries来显示两条曲线,并使用定时器Timer1来动态更新曲线的数据。在定时器的事件中,调用AddRandomData方法生成随机的曲线数据点,并通过Chart1.AutoRepaint := True来实时刷新图表显示。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值