笛卡尔平面的计算区域



PHP与GD我在笛卡尔平面上建立了一个四边形。我测量了4条边,每个边的结果=100(角是90度)。高斯面积计算公式。https://en.wikipedia.org/wiki/Shoelace_formula面积是10000,但我的结果是15000?错误在哪里?谢谢你的帮助。

    $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);

你需要用初始的堇青石来结束鞋带配方。

$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]);

相关内容

  • 没有找到相关文章

最新更新