zoukankan      html  css  js  c++  java
  • 计算交点以及是否在直线内

    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;

  • 相关阅读:
    IE6-IE11兼容性问题列表及解决办法
    EJB--事务管理 .
    JDBC批处理---(java 对数据库的回滚) .
    redisb并发访问慢出现的问题
    redis其他问题
    多线程实现服务器端接收连接
    序列化作用
    redis的key过期时间
    nginx负载均衡和反向代理有什么区别
    nginx的负载均衡和反响代理配置
  • 原文地址:https://www.cnblogs.com/jeenmablog/p/12082892.html
Copyright © 2011-2022 走看看