zoukankan      html  css  js  c++  java
  • 求多边形的面积

    const MaxPointNum = 65535;
    type
       PXY = ^TXY;
       TXY = record             // 点的数据结构
          x, y: single;
       end;
       XYArray = array[0..MaxPointNum] of TXY;
       PXYArray = ^XYArray;     //  线/面的数据结构

    // 积分方法求多边形/面状图形的面积
    // 多边形坐标在 xys 中,点数在 nn 中
    function AreaOfPolygon(xys: PXYArray; nn: integer):single;
    var ii:integer;
        ss: single;
    begin
       ss := 0;
       for ii := 0 to nn-2 do
           ss := ss + (xys^[ii].y+xys^[ii+1].y) * (xys^[ii].x-xys^[ii+1].x) / 2;
       result := abs(ss);
    end;

    // 判别点(x,y)是否落在多边形内
    // 多边形坐标在 xys 中,点数在 nn 中
    function isPtInRegion(x, y: single; xys: PXYArray; nn: integer): boolean;
    var ii, ncross : integer;
        yt, x0, y0, x1, y1, x2, y2 : single;
    begin
       ncross := 0;
       x0 := x;   y0 := y;
       for ii := 0 to nn-2 do begin
          x1 := xys^[ii].X;     y1 := xys^[ii].Y;
          x2 := xys^[ii+1].X;   y2 := xys^[ii+1].Y;
          if((x0>=x1) and (x0=x2) and (x00) and ((ncross mod 2) = 1)) then Result := True
                                                else Result := FALSE;
    end;

  • 相关阅读:
    docker三剑客之docker compose
    docker三剑客之一docker compose
    dockerfile创建镜像(二)
    dockerfile创建镜像
    dockerfile创建镜像
    端口映射和容器映射
    鼠标点击左侧字母,字母变色
    body滚动时左侧菜单固定
    左侧菜单收缩展开
    车林通购车之家--购车计算器模块--算法js
  • 原文地址:https://www.cnblogs.com/yzryc/p/6374125.html
Copyright © 2011-2022 走看看