Oct
6

PHP를 사용하여 한 경계 상자의 크기를 다른 경계 상자와 비교하여 계산하는 방법

10/06/2023 01:21 AM ~에 의해 Admin 입력 Php


이 튜토리얼에서는 다른 경계 상자에 대한 하나의 경계 상자의 크기를 알아봅니다. 먼저 경계 상자를 $box로 정의하고 $box2로 위치를 정의하겠습니다.

$box1 = array(
    'x_min' => -0.462,
    'y_min' => -120.329,
    'x_max' => 94.77,
    'y_max' => -3.674,
);

$box2 = array(
    'x_min' => -0.247,
    'y_min' => -5.025,
    'x_max' => 3.939,
    'y_max' => 0.301,
);

다음으로 각 경계 상자의 너비와 높이를 계산합니다.

$box1_width = $box1['x_max'] - $box1['x_min'];
$box1_height = $box1['y_max'] - $box1['y_min'];
$box2_width = $box2['x_max'] - $box2['x_min'];
$box2_height = $box2['y_max'] - $box2['y_min'];

다음으로 각 경계 상자의 면적을 계산합니다.

$box1_area = $box1_width * $box1_height;
$box2_area = $box2_width * $box2_height;

다음으로 첫 번째 경계 상자에 대한 두 번째 경계 상자의 크기 비율을 계산합니다.

$size_percentage = ($box2_area / $box1_area) * 100;
$size_percentage = round($size_percentage, 2);

다음은 전체 코드입니다.

<?php

$box1 = array(
    'x_min' => -0.462,
    'y_min' => -120.329,
    'x_max' => 94.77,
    'y_max' => -3.674,
);

$box2 = array(
    'x_min' => -0.247,
    'y_min' => -5.025,
    'x_max' => 3.939,
    'y_max' => 0.301,
);

// Calculate the width and height of each bounding box
$box1_width = $box1['x_max'] - $box1['x_min'];
$box1_height = $box1['y_max'] - $box1['y_min'];
$box2_width = $box2['x_max'] - $box2['x_min'];
$box2_height = $box2['y_max'] - $box2['y_min'];

// Calculate the area of each bounding box
$box1_area = $box1_width * $box1_height;
$box2_area = $box2_width * $box2_height;

// Calculate the size percentage of the second bounding box with respect to the first one
$size_percentage = ($box2_area / $box1_area) * 100;
$size_percentage = round($size_percentage, 2);

// Print the size percentage
echo "The size percentage of the second bounding box with respect to the first one is: " . $size_percentage . "%";

당신의 생각

검색
스폰서
크립토워치
우리를 따르라
공지 사항

새로운 도구가 추가되었습니다: SVG 확대/축소 치수 계산기.

스폰서