-
Lenguaje
JavaScript
-
Descripción
Calcula la distancia entre dos puntos de coordenadas conocidas.
La fórmula final a despejar es:
D² = (X₂-X₁)² + (Y₂-Y₁)²
Donde:
(D) La distancia entre dos puntos.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "https://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>Distancia entre dos puntos de coordenadas</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<script>
<html>
<head>
<title>Distancia entre dos puntos de coordenadas</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<script>
function algoritmo()
{
let distancia, x1, x2, y1, y2;
x1 = parseFloat (document.formulario1.x1.value);
x2 = parseFloat (document.formulario1.x2.value);
y1 = parseFloat (document.formulario1.y1.value);
y2 = parseFloat (document.formulario1.y2.value);
distancia=Math.sqrt((x2-x1)*(x2-x1)+(y2-y1)*(y2-y1));
document.formulario1.distancia.value = distancia;
}
{
let distancia, x1, x2, y1, y2;
x1 = parseFloat (document.formulario1.x1.value);
x2 = parseFloat (document.formulario1.x2.value);
y1 = parseFloat (document.formulario1.y1.value);
y2 = parseFloat (document.formulario1.y2.value);
distancia=Math.sqrt((x2-x1)*(x2-x1)+(y2-y1)*(y2-y1));
document.formulario1.distancia.value = distancia;
}
</script>
</head>
<body>
<form name="formulario1">
<table style="text-align: left; margin-left: auto; margin-right: auto;">
<tbody>
<tr>
<td>
<label for="x1">Ingresa el valor de x1:</label>
</td>
<td>
<input name="x1" required="required" step="0.000001" type="number" />
</td>
</tr>
<tr>
<td>
<label for="x2">Ingresa el valor de x2:</label>
</td>
<td>
<input name="x2" required="required" step="0.000001" type="number" />
</td>
</tr>
<tr>
<td>
<label for="y1">Ingresa el valor de y1:</label>
</td>
<td>
<input name="y1" required="required" step="0.000001" type="number" />
</td>
</tr>
<tr>
<td>
<label for="y2">Ingresa el valor de y2:</label>
</td>
<td>
<input name="y2" required="required" step="0.000001" type="number" />
</td>
</tr>
<tr align="center">
<td colspan="2" rowspan="1">
<input value="Procesar" type="button" onclick="algoritmo();" />
<input type="reset" />
</td>
</tr>
<tr>
<td>
<label for="distancia">Valor de distancia:</label>
</td>
<td>
<input name="distancia" step="0.000001" type="number" />
</td>
</tr>
</tbody>
</table>
</form>
</body>
</html>
</head>
<body>
<form name="formulario1">
<table style="text-align: left; margin-left: auto; margin-right: auto;">
<tbody>
<tr>
<td>
<label for="x1">Ingresa el valor de x1:</label>
</td>
<td>
<input name="x1" required="required" step="0.000001" type="number" />
</td>
</tr>
<tr>
<td>
<label for="x2">Ingresa el valor de x2:</label>
</td>
<td>
<input name="x2" required="required" step="0.000001" type="number" />
</td>
</tr>
<tr>
<td>
<label for="y1">Ingresa el valor de y1:</label>
</td>
<td>
<input name="y1" required="required" step="0.000001" type="number" />
</td>
</tr>
<tr>
<td>
<label for="y2">Ingresa el valor de y2:</label>
</td>
<td>
<input name="y2" required="required" step="0.000001" type="number" />
</td>
</tr>
<tr align="center">
<td colspan="2" rowspan="1">
<input value="Procesar" type="button" onclick="algoritmo();" />
<input type="reset" />
</td>
</tr>
<tr>
<td>
<label for="distancia">Valor de distancia:</label>
</td>
<td>
<input name="distancia" step="0.000001" type="number" />
</td>
</tr>
</tbody>
</table>
</form>
</body>
</html>