Files
2025-05-21 11:11:37 +02:00

54 lines
2.0 KiB
PHP

<!doctype html>
<html lang="pl">
<head>
<meta charset="UTF-8">
<meta name="viewport"
content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Z31 - Pole z wierzchołków</title>
<link rel="stylesheet" href="style.css">
</head>
<body>
<header>
<h1>Zadanie Z31</h1>
<h2>Autor: Jakub Grzegorczyk</h2>
</header>
<div class="box">
Napisz program, który: dla współrzędnych wierzchołka trójkąta (x1,y1), (x2,y2),(x3,y3), oblicza jego pole powierzchni
<img src="img.png" alt="Wzór">
</div>
<div class="box">
<form action="index.php" method="post">
<label for="x1">Podaj x<sub>1</sub>: </label><br>
<input type="number" name="x1" id="x1"><br><br>
<label for="y1">Podaj y<sub>1</sub>: </label><br>
<input type="number" name="y1" id="y1"><br><br>
<label for="x2">Podaj x<sub>2</sub>: </label><br>
<input type="number" name="x2" id="x2"><br><br>
<label for="y2">Podaj y<sub>2</sub>: </label><br>
<input type="number" name="y2" id="y2"><br><br>
<label for="x3">Podaj x<sub>3</sub>: </label><br>
<input type="number" name="x3" id="x3"><br><br>
<label for="y3">Podaj y<sub>3</sub>: </label><br>
<input type="number" name="y3" id="y3"><br><br>
<button type="submit">Oblicz</button>
<br>
</form>
</div>
<div class="box">
<?php
if ($_SERVER['REQUEST_METHOD'] == 'POST') {
$x1 = (float)htmlspecialchars($_POST['x1']);
$y1 = (float)htmlspecialchars($_POST['y1']);
$x2 = (float)htmlspecialchars($_POST['x2']);
$y2 = (float)htmlspecialchars($_POST['y2']);
$x3 = (float)htmlspecialchars($_POST['x3']);
$y3 = (float)htmlspecialchars($_POST['y3']);
$pole = abs(($x1 * ($y2 - $y3) + $x2 * ($y3 - $y1) + $x3 * ($y1 - $y2)) / 2);
echo "Pole powierzchni trójkąta wynosi: " . round($pole, 2);
}
?>
</div>
</body>
</html>