xxxxxxxxxx
// Formula
// a^2 + b^2 = c^2
// base as a leg
// altitude as b leg
// hypotenuse as c leg
function pythagorean(base,altitude,hypotenuse) {
if (base=== "?") {
let bSqure= altitude*altitude
let cSqure= hypotenuse*hypotenuse
let aSqure= cSqure - bSqure
return Math.sqrt(aSqure)
}
if (altitude === "?") {
let aSqure= base*base
let cSqure= hypotenuse*hypotenuse
let bSqure= cSqure - aSqure
return Math.sqrt(bSqure)
}
if (hypotenuse === "?") {
return Math.sqrt( base*base + altitude*altitude)
}
}
console.log(pythagorean("?",5,13));
console.log(pythagorean(6,8,"?"));
console.log(pythagorean(3,4,"?"));
console.log(pythagorean('?',8,16));
console.log(pythagorean(5,5,"?"));
xxxxxxxxxx
The Pythagorean Theorem states that the sum of the squares on the legs
of a right triangle is equal to the square on the hypotenuse.
* a^2 + b^2 = c^2
* *
* *
* c */| * * * * * *
* / | *
* / | b *
* / _| *
*/______|_| * * * * * *
* *
* a *
* * * * * *
It can be extended to higher dimensions! 3d example:
height^2 + width^2 + deph^2 = hypotenuse^2
xxxxxxxxxx
public class PythagoreanTheorem {
public static void main(String args[]) {
double a=4;
double b=5;
double c = Math.sqrt(a * a + b * b);
System.out.println("c = " + c);
}
}
xxxxxxxxxx
import math
class point:
def __init__(self, x, y, z):
self.x = x
self.y = y
self.z = z
p1 = point(10,14,0)
p2 = point(14,14,0)
distanceByTwoPoints = math.sqrt((p1.y-p2.y)**2 + (p1.x-p2.x)**2)
xxxxxxxxxx
class Point():
def __init__(self,x,y):
self.x = x
self.y = y
def distance(a,b):
#legA = abs(a.x - b.x)
#legB = abs(a.y - b.y)
#legC2 = (legA**2)+(legB**2)
#legC = legC2 ** 0.5
#return legC
return ((abs(a.x-b.x)**2)+(abs(a.y-b.y)**2))**0.5
print(distance(Point(-3,3),Point(5,-5)))
xxxxxxxxxx
import math
print("\n")
print("_____________________Pythagorean Theorem with Python__________________________________")
print("___________________________created by THARCHEN________________________________________")
print("\n")
print("Please note the following indications\n")
print("a is the base of the triangle\n")
print("b is the height of the triangle\n")
print("c is the hypotenus of the triangle\n")
side = input("Give the side you want to solve for (a, b, or c): ")
if side == "a":
print("\n")
print("Let us find the base of the triangle\n")
b = float(input("Height: "))
c = float(input("Hypotenuse: "))
a = math.sqrt(c ** 2 - b ** 2)
print("Base of the triangle is", "%.2f" %a)
print("\n")
elif side == "b":
print("Let us find the height of the triangle\n")
a = float(input("Base: "))
c = float(input("Hypotenuse: "))
b = math.sqrt(c ** 2 - a ** 2)
print("Height of the triangle is","%.2f" %b)
elif side == "c":
print("Let us find the hypotenuse of the traingle\n")
a = float(input("Base: "))
b = float(input("Height: "))
c = math.sqrt(a ** 2 + b ** 2)
print("Hypotenuse of the triangle is","%.2f" %c)
else:
print("The value of hypotenuse is always greater than height and base")
def triangle():
print(" .")
print(" /|")
print(" / |")
print(" / |")
print(" / |")
print(" / |")
print(" / |")
print(" / |")
def traingle_1():
print(" ","%.2f" %c, " ","%.2f" %b)
def triangle_2():
print(" / |")
print(" / |")
print(" / |")
print(" / |")
print(" / |")
print(" / |")
print("/___","%.2f"%a,"____|\n")
triangle()
traingle_1()
triangle_2()