dongyan1936 2015-12-27 14:24
浏览 106

计算区域与笛卡尔平面

PHP with GD I built a quadrangle on the Cartesian plane. I measured the 4 sides, result = 100 each (the corners are at 90 degrees). Area calculation formula of Gauss. https://en.wikipedia.org/wiki/Shoelace_formula Area doverebbe be 10,000, but my result is 15,000? Where is the mistake? Thanks for your help.

    $Image = imagecreate(400,400);
    imagecolorallocate($Image,0,0,0);
    $White = imagecolorallocate($Image,255,255,255);

    $p[0] = 100; $p[1] = 200;$p[2] = 200; 
    $p[3] = 200;$p[4] = 200; $p[5] = 300;$p[6] = 100; $p[7] = 300;

    $XY = array(
    $p[0], $p[1], // section of the line $p[2], $p[3]
    $p[2], $p[3], // section of the line $p[4], $p[5]
    $p[4], $p[5], // section of the line $p[6], $p[7]
    $p[6], $p[7] // section of the line $p[0], $p[1]
            );  

    imagepolygon($Image, $XY, 4, $White);           

    // segment
    $SegmentLengthA = sqrt(bcpow($p[0]-$p[2],2) + bcpow($p[1]-$p[3],2));
    imagestring ($Image , 5 , 10 , 5 , "LunghSegmA = $SegmentLengthA" , $White );

    $SegmentLengthB = sqrt(bcpow($p[2]-$p[4],2) + bcpow($p[3]-$p[5],2));
    imagestring ($Image , 5 , 10 , 20 , "LunghSegmB = $SegmentLengthB" , $White );


    $SegmentLengthC = sqrt(bcpow($p[4]-$p[6],2) + bcpow($p[5]-$p[7],2));
    imagestring ($Image , 5 , 10 , 35 , "LunghSegmC = $SegmentLengthC" , $White );


    $SegmentLengthD = sqrt(bcpow($p[6]-$p[0],2) + bcpow($p[7]-$p[1],2));
    imagestring ($Image , 5 , 10 , 50 , "LunghSegmC = $SegmentLengthC" , $White );

    ////// perimeter
    $Perimeter = $SegmentLengthA + $SegmentLengthB + $SegmentLengthC + $SegmentLengthD;
    imagestring ($Image , 5 , 10 , 65 , "Perimeter = $Perimeter" , $White );

    // area
    $L1 = ($p[0] * $p[3]) + ($p[2] * $p[5]) + ($p[4] * $p[7]);
    $L2 = ($p[1] * $p[2]) + ($p[3] * $p[4]) + ($p[5] * $p[6]);
    $Area = abs($L1 - $L2) / 2;
    imagestring ($Image , 5 , 10 , 80 , "Area = $Area" , $White );

    imagepng($Image);
  • 写回答

1条回答 默认 最新

  • doufei2328 2015-12-27 15:12
    关注

    You need to end shoelace formula with initial cordinates.

    $L1 = ($p[0] * $p[3]) + ($p[2] * $p[5]) + ($p[4] * $p[7]) + ($p[6] * $p[1]);
    $L2 = ($p[1] * $p[2]) + ($p[3] * $p[4]) + ($p[5] * $p[6]) + ($p[7] * $p[0]);
    
    评论

报告相同问题?

悬赏问题

  • ¥15 yolov8边框坐标
  • ¥15 matlab中使用gurobi时报错
  • ¥15 WPF 大屏看板表格背景图片设置
  • ¥15 这个主板怎么能扩出一两个sata口
  • ¥15 不是,这到底错哪儿了😭
  • ¥15 2020长安杯与连接网探
  • ¥15 关于#matlab#的问题:在模糊控制器中选出线路信息,在simulink中根据线路信息生成速度时间目标曲线(初速度为20m/s,15秒后减为0的速度时间图像)我想问线路信息是什么
  • ¥15 banner广告展示设置多少时间不怎么会消耗用户价值
  • ¥16 mybatis的代理对象无法通过@Autowired装填
  • ¥15 可见光定位matlab仿真