求两条直线的交点

CvPoint GetTwoLineCrossPoint(const int& x1, const int& y1, const int& x2, const int& y2,     const int& x3, const int& y3, const int& x4, const int& y4)
{
    //第一条直线的参数
    double a0 = y1 - y2;
    double b0 = x2 - x1;
    double c0 = x1 * y2 - x2 * y1;

    //第二条直线的参数
    double a1 = y3 - y4;
    double b1 = x4 - x3;
    double c1 = x3 * y4 - x4 * y3;

    //求交点
    double D = a0 * b1 - a1 * b0;

    if (fabs(D) < 0.00001)
    {
        return cvPoint(-1, -1);
    }

    CvPoint p;
    p.x=(int)((b0 * c1 - b1 * c0) / D);
    p.y=(int)((c0 * a1 - c1 * a0) / D);

    return p;
}
时间: 2024-08-02 10:53:15

求两条直线的交点的相关文章

Intersecting Lines--POJ1269(判断两条直线的关系 &amp;&amp; 求两条直线的交点)

http://poj.org/problem?id=1269 我今天才知道原来标准的浮点输出用%.2f   并不是%.2lf  所以wa了好几次 题目大意:   就给你两个线段 然后求这两个线段所在的直线的关系  有共线  平行  和相交 #include<stdio.h> #include<string.h> #include<stdlib.h> #include<ctype.h> #include<math.h> #define N 200

AS3 求两条直线的交点

//粘贴到帧上运行即可 var p1Start:Point = new Point(0,0); var p1End:Point = new Point(50,50); var p2Start:Point = new Point(50,50); var p2End:Point = new Point(100,100); var p:Point = new Point(); trace(checkPoint()) function checkPoint() { if (p1Start.x == p1

求平面内两条直线的交点

The  and  coordinates of the point of intersection of two non-vertical lines can easily be found using the following substitutions and rearrangements. Suppose that two lines have the equations  and  where  and  are the slopes (gradients) of the lines

计算两条直线的交点(C#)

从其他地方看到的源码是有问题的. /// <summary> /// 计算两条直线的交点 /// </summary> /// <param name="lineFirstStar">L1的点1坐标</param> /// <param name="lineFirstEnd">L1的点2坐标</param> /// <param name="lineSecondStar"

求两条直线(线段)的交点

转自: http://blog.csdn.net/dgq8211/article/details/7952825 如图,如何求得直线 AB 与直线 CD 的交点P? 以上内容摘自<算法艺术与信息学竞赛>. 思路就是利用叉积求得点P分线段DC的比,然后利用高中学习的定比分点坐标公式求得分点P的坐标. 看不懂的可以去复习下 定比分点 的知识. 1 #include <math.h> 2 #include <stdio.h> 3 #include <string.h&g

求两个一次函数的交点

Point2f pointIntersection(Point2f p1, Point2f p2, Point2f p3, Point2f p4) { //p1,p2所在一条直线,p3,p4所在一条直线,求两条直线的交点 //p1,p2所成的直线 BOOL flag1=FALSE,flag2=FALSE; Point2f p;//存放最后的交点 float k1,k2,b1,b2; if(p2.x==p1.x)//分母不能为0 p.x=p2.x; else { flag1=TRUE; k1=(p

判断两条直线的位置关系 POJ 1269 Intersecting Lines

两条直线可能有三种关系:1.共线     2.平行(不包括共线)    3.相交. 那给定两条直线怎么判断他们的位置关系呢.还是用到向量的叉积 例题:POJ 1269 题意:这道题是给定四个点p1, p2, p3, p4,直线L1,L2分别穿过前两个和后两个点.来判断直线L1和L2的关系 这三种关系一个一个来看: 1. 共线. 如果两条直线共线的话,那么另外一条直线上的点一定在这一条直线上.所以p3在p1p2上,所以用get_direction(p1, p2, p3)来判断p3相对于p1p2的关

poj1039——计算几何 求直线与线段交点,判断两条直线是否相交

poj1039——计算几何  求直线与线段交点,判断两条直线是否相交 Pipe Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 9439   Accepted: 2854 Description The GX Light Pipeline Company started to prepare bent pipes for the new transgalactic light pipeline. During the de

判断两条直线是否相交点

#pragma mark ------------ 判断两条直线是否相交 + (BOOL)checkLineIntersection:(CGPoint)p1 p2:(CGPoint)p2 p3:(CGPoint)p3 p4:(CGPoint)p4 {     CGFloat denominator = (p4.y - p3.y) * (p2.x - p1.x) - (p4.x - p3.x) * (p2.y - p1.y);          if (denominator == 0.0f) {