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;

  • 相关阅读:
    Android的webview的设置参数
    禁止RecycleView滑动
    Volley加载不出图片的问题
    LIstview滑动时不加载图片,停止时加载!
    【原创】设计模式开篇—面向对象的软件设计
    [原创]写给自己的总结—2014到2015
    【原创】开车分四个阶段的话,你属于哪个
    【原创】亲身经历的几次合同陷阱
    【转】程序员需谨记的8条团队开发原则
    【转】绩效考核的10大误区
  • 原文地址:https://www.cnblogs.com/jeenmablog/p/12082892.html
Copyright © 2011-2022 走看看