function  CrossPoint(  )
%% 求两条直线的交点坐标
x1 = [7.8 8];
y1 = [0.96 0.94];
%line2
x2 = [8.25 8.25];
y2 = [0 0.99];
%fit linear polynomial
p1 = polyfit(x1,y1,1);
p2 = polyfit(x2,y2,1);
%calculate intersection
x_intersect = fzero(@(x) polyval(p1-p2,x),3);
y_intersect = polyval(p1,x_intersect);
line(x1,y1);
hold on;
line(x2,y2);
plot(x_intersect,y_intersect,'r*')
axis([5,10,0,2]); %% 求线段的交点坐标
n=20;
p=rand(n,4); %(x1,y1,x2,y2)线段两端点 for i=1:n
pbar=p(i,:);
pbar=reshape(pbar,[2,2]);
line(pbar(1,:),pbar(2,:));
end hold on;
for i=1:n-1
p1=p(i,:);
k1=(p1(2)-p1(4))/(p1(1)-p1(3));
b1=p1(2)-k1*p1(1);
for j=i+1:n
p2=p(j,:);
k2=(p2(2)-p2(4))/(p2(1)-p2(3));
b2=p2(2)-k2*p2(1); x=-(b1-b2)/(k1-k2); %求两直线交点
y=-(-b2*k1+b1*k2)/(k1-k2);
%判断交点是否在两线段上
if min(p1(1),p1(3))<=x && x<=max(p1(1),p1(3)) && ...
min(p1(2),p1(4))<=y && y<=max(p1(2),p1(4)) && ...
min(p2(1),p2(3))<=x && x<=max(p2(1),p2(3)) && ...
min(p2(2),p2(4))<=y && y<=max(p2(2),p2(4))
plot(x,y,'r.');
end
end
end
end

MATLAB—求直线或者线段之间的交点坐标的更多相关文章

  1. Segments--poj3304(判断直线与线段之间的关系)

    http://poj.org/problem?id=3304 给你几条线段  然后 让你找到一条直线让他在这条直线上的映射有一个重合点 如果有这条直线的话  这个重合的部分的两个端点一定是某两条线段的 ...

  2. poj 3304 Segments(计算直线与线段之间的关系)

    Segments Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 10921   Accepted: 3422 Descrip ...

  3. matlab画直线,指定斜率与x坐标范围

    闲话不说,直接上代码与图的效果!

  4. MATLAB求马氏距离(Mahalanobis distance)

    MATLAB求马氏距离(Mahalanobis distance) 作者:凯鲁嘎吉 - 博客园 http://www.cnblogs.com/kailugaji/ 1.马氏距离计算公式 d2(xi,  ...

  5. POJ 1039 Pipe(直线和线段相交判断,求交点)

    Pipe Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 8280   Accepted: 2483 Description ...

  6. hdu 2857:Mirror and Light(计算几何,点关于直线的对称点,求两线段交点坐标)

    Mirror and Light Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) ...

  7. POJ_1269_Intersecting Lines_求直线交点

    POJ_1269_Intersecting Lines_求直线交点 Description We all know that a pair of distinct points on a plane ...

  8. poj 1269 Intersecting Lines——叉积求直线交点坐标

    题目:http://poj.org/problem?id=1269 相关知识: 叉积求面积:https://www.cnblogs.com/xiexinxinlove/p/3708147.html什么 ...

  9. UVa 11437:Triangle Fun(计算几何综合应用,求直线交点,向量运算,求三角形面积)

    Problem ATriangle Fun Input: Standard Input Output: Standard Output In the picture below you can see ...

随机推荐

  1. HDFS简单测试

    使用Hadoop的Java客户端API操作分布式文件系统#获取文件系统实现//hdfs://master01:9000/FileSystem get(URI uri[,Configuration co ...

  2. [转]OmniLayer / omnicore API 中文版

    本文转自:https://www.codetd.com/article/1692438 JSON-RPC API Omni Core是Bitcoin Core的一个分支,其Omni协议功能支持作为顶层 ...

  3. [转]Windows Server 2016 服务器IIS配置

    本文转自:https://blog.csdn.net/corson/article/details/82185407 多余的话就不说了,配置Windows Server 2016服务器具体如下图    ...

  4. [转]c# System.IO.Ports SerialPort Class

    本文转自:https://docs.microsoft.com/en-us/dotnet/api/system.io.ports.serialport?redirectedfrom=MSDN& ...

  5. ASP.NET MVC 学习笔记-5.Controller与View的数据传递

    ViewData属性 ViewData属性是System.Web.Mvc.ControllerBase中的一个属性,它相当于一个数据字典.Controller中向该字典写入数据,ViewData[“K ...

  6. 我是这样搞懂一个神奇的BUG

    摘要: 通过分析用户的行为,才想得到为什么会出现这种情况! 前两天在BearyChat收到这样的一个报警消息: 409 ?Conflict ? 平时很少遇到这样的错误,貌似很严重的样子,吓得我赶紧查看 ...

  7. CSS :root 测试

    <!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title> ...

  8. es6 语法 (数值扩展)

    { //二进制数值都是0b开头,八进制0o console.log(0b111110111) console.log(0o767); } { console.log('15',Number.isFin ...

  9. sublime text2 中标签高亮效果BracketHighlighter插件

    1.打开package Control,选择install Package 2.输入BracketHighlighter,回车 3.这样该插件会自动安装,安装后所有的提示高亮都是白色或没有提示.按 p ...

  10. 2018-12-03 VS Code英汉词典插件v0.0.7-尝试词性搭配

    续上文VS Code英汉词典插件v0.0.6-改为TS实现, 加测试后, 继续重构(提取常量, 避免var, 添加类型等等), 并完善测试. 测试方法参考: Testing Visual Studio ...