Oct
6

Comment calculer la taille d'un cadre de délimitation par rapport à un autre en utilisant PHP

10/06/2023 01:21 AM par Admin dans Php


Dans ce didacticiel, nous trouverons la taille d'un cadre de délimitation par rapport à un autre cadre de délimitation. Définissons d'abord nos cadres de délimitation comme $box et $box2 et définissons leur emplacement.

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

Calculez ensuite la largeur et la hauteur de chaque cadre de délimitation.

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

Ensuite, nous calculerons l’aire de chaque cadre de délimitation.

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

Ensuite, nous calculons le pourcentage de taille de la deuxième boîte englobante par rapport à la première.

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

Voici le code global.

<?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 . "%";

Tes pensées

Rechercher
PARRAINER
CRYPTOWATCH
SUIVEZ NOUS
derniers tweets

Nouvel outil ajouté : Calculateur de dimensions de zoom SVG.

PARRAINER