def triangle_area_loop(): '''() -> number Return the area of a triangle with dimentions base and height given by the user. ''' base = int(input("enter the triangle's base: ")) height = int(input("enter the triangle's height: ")) area = triangle_area.triangle_area(base, height) return area
def triangle_monomial_integral(i, j, t): #*****************************************************************************80 # ## TRIANGLE_MONOMIAL_INTEGRAL integrates a monomial over an arbitrary triangle. # # Location: # # http://people.sc.fsu.edu/~jburkardt/py_src/triangle_integrals/triangle_monomial_integral.py # # Licensing: # # This code is distributed under the GNU LGPL license. # # Modified: # # 23 April 2015 # # Author: # # John Burkardt # # Parameters: # # Input, integer I, J, the exponents of X and Y in the monomial. # 0 <= I, J. # # Input, real T(2,3), the vertices of the triangle. # # Output, real Q, the integral of X^I * Y^J over triangle T. # import numpy as np from poly_power_linear import poly_power_linear from poly_product import poly_product from rs_to_xy_map import rs_to_xy_map from triangle_area import triangle_area from triangle01_poly_integral import triangle01_poly_integral # # Get map coefficients from reference RS triangle to general XY triangle. # R = a+b*X+c*Y # S = d+e*X+f*Y # a, b, c, d, e, f = rs_to_xy_map(t) # # Compute # P1(R,S) = (a+b*R+c*S)^i. # P2(R,S) = (d+e*R+f*S)^j. # d1 = 1 p1 = np.array([a, b, c]) dp1, pp1 = poly_power_linear(d1, p1, i) d2 = 1 p2 = np.array([d, e, f]) dp2, pp2 = poly_power_linear(d2, p2, j) # # Compute the product # P3(R,S) = (a+b*R+c*S)^i * (d+e*R+f*S)^j. # d3, p3 = poly_product(dp1, pp1, dp2, pp2) # # Compute the integral of P3(R,S) over the reference triangle. # q = triangle01_poly_integral(d3, p3) # # Multiply by the area of the physical triangle T(X,Y) divided by # the area of the reference triangle. # q = q * triangle_area(t) / 0.5 return q
def test_triangle_area_side_length_0(self): eq_(0, triangle_area(0))
def test_triangle_area_side_length10(self): eq_(55, triangle_area(10))
def test_triangle_area_side_length_negative(self): eq_(0, triangle_area(-5))
def test_triangle_area_side_length_1(self): eq_(1, triangle_area(1))
def test_triangle_area_side_length2(self): eq_(3, triangle_area(2))