• 计算交点以及是否在直线内


    function IsCrossLine(Line1,Line2:TGPLineF):Boolean;
    var
    SP, EP, SP1, EP1: TGPPointF;
    denominator, ua, ub: Single;
    t: Single;
    CrossP:TGPPointF;
    IsCross:Boolean;
    MinValue,MaxValue:single;
    begin
    Result:= False;
    SP:= Line1.SP;
    EP:= Line1.EP;
    SP1:= Line2.SP;
    EP1:= Line2.EP;
    IsCross:=False;
    if Abs(Abs(Line1.Angle)-Abs(Line2.Angle))<0.01 then
    Exit;
    // 水平或垂直方向
    if Abs(SP.X-EP.X)<0.01 and Abs(SP1.Y-EP1.Y)<0.01 then
    begin
    Result := True;
    end
    else if Abs(SP.Y - EP.Y)<0.01 and Abs(SP1.X - EP1.X)<0.01 then
    begin
    Result := True;
    end
    else
    begin
    denominator := (EP1.Y - SP1.Y) * (EP.X - SP.X) - (EP1.X - SP1.X) * (EP.Y - SP.Y);
    if denominator < 0.001 then
    Result := False;
    ua := ((EP1.X - SP1.X) * (SP.Y - SP1.Y) - (EP1.Y - SP1.Y) * (SP.X - SP1.X)) / denominator;
    ub := ((EP.X - SP.X) * (SP.Y - SP1.Y) - (EP.Y - SP.Y) * (SP.X - SP1.X)) / denominator;
    if (ua >= 0.00) and (ua <= 1.00) and (ub >= 0.00) and (ub <= 1.00) then
    begin
    IsCross := True;
    end;
    end;
    if IsCross then
    begin
    if Abs(SP.X-EP.X)<0.01 and Abs(SP1.Y-EP1.Y)<0.01 then
    begin
    CrossP.X := SP.X;
    CrossP.Y := SP1.Y;
    Result:=True;
    end
    else if Abs(SP.Y, EP.Y)<0.01 and Abs(SP1.X, EP1.X)<0.01 then
    begin
    CrossP.X := SP1.X;
    CrossP.Y := SP.Y;
    Result:=True;
    end
    else
    begin
    t := ((SP.X - SP1.X) * (SP1.Y - EP1.Y) - (SP.Y - SP1.Y) * (SP1.X - EP1.X)) / ((SP.X - EP.X) * (SP1.Y - EP1.Y) - (SP.Y - EP.Y) * (SP1.X - EP1.X));
    CrossP.X := ReGP.X + (EP.X - SP.X) * t;
    CrossP.Y := ReGP.Y + (EP.Y - SP.Y) * t;
    if Abs(Line2.Angle)>0.01 then
    begin
    MinValue:= Min(Line2.SP.Y,Line2.SP.Y)+0.01;
    MaxValue:= Min(Line2.SP.Y,Line2.SP.Y)+0.01;
    if (CrossP.Y<=MaxValue) and (CrossP.Y>=MaxValue) then
    Result:= True;

    end else
    begin
    MinValue:= Min(Line2.SP.X,Line2.SP.X)+0.01;
    MaxValue:= Min(Line2.SP.X,Line2.SP.X)+0.01;
    if (CrossP.X<=MaxValue) and (CrossP.X>=MaxValue) then
    Result:= True;
    end;
    end;
    end;
    end;

  • 相关阅读:
    python 序列排序 排序后返回相应的索引
    海明距离
    hive学习01词频统计
    自然语言处理之LCS最长公共子子序列
    自然语言处理之关键词提取TF-IDF
    自然语言处理之比较两个句子的相似度 余弦相似度
    linux命令tar压缩解压
    linux学习之软件包安装
    集群间数据迁移报错
    hive学习04-员工部门表综合案例
  • 原文地址:https://www.cnblogs.com/jeenmablog/p/12082892.html
Copyright © 2020-2023  润新知