From 1bedf32949e0e378533b12dc30ea3d47b4fef4fd Mon Sep 17 00:00:00 2001 From: ieshaan12 Date: Fri, 16 Oct 2020 12:24:30 +0530 Subject: [PATCH] Two Point distance --- mathgenerator/mathgen.py | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/mathgenerator/mathgen.py b/mathgenerator/mathgen.py index 9918cd0..e6b529a 100644 --- a/mathgenerator/mathgen.py +++ b/mathgenerator/mathgen.py @@ -276,6 +276,16 @@ def factoringFunc(range_x1 = 10, range_x2 = 10): solution = f"(x{x1})(x{x2})" return problem, solution +def distanceTwoPoints(maxValXY = 20, minValXY=-20): + point1X = random.randint(minValXY, maxValXY+1) + point1Y = random.randint(minValXY, maxValXY+1) + point2X = random.randint(minValXY, maxValXY+1) + point2Y = random.randint(minValXY, maxValXY+1) + distanceSq = (point1X - point2X) ** 2 + (point1Y - point2Y) ** 2 + solution = f"sqrt({distanceSq})" + problem = f"Find the distance between ({point1X}, {point1Y}) and ({point2X}, {point2Y})" + return problem, solution + # || Class Instances #Format is: @@ -301,4 +311,5 @@ intMatrix22Multiplication = Generator("Integer Multiplication with 2x2 Matrix", areaOfTriangle = Generator("Area of Triangle", 18, "Area of Triangle with side lengths a, b, c = ", "area", areaOfTriangleFunc) doesTriangleExist = Generator("Triangle exists check", 19, "Does triangle with sides a, b and c exist?","Yes/No", isTriangleValidFunc) midPointOfTwoPoint=Generator("Midpoint of the two point", 20,"((X1,Y1),(X2,Y2))=","((X1+X2)/2,(Y1+Y2)/2)",MidPointOfTwoPointFunc) -factoring = Generator("Subtraction", 21, "x^2+(x1+x2)+x1*x2", "(x-x1)(x-x2)", factoringFunc) \ No newline at end of file +factoring = Generator("Subtraction", 21, "x^2+(x1+x2)+x1*x2", "(x-x1)(x-x2)", factoringFunc) +distance2Point = Generator("Distance between 2 points", 22, "Find the distance between (x1,y1) and (x2,y2)","sqrt(distanceSquared)", distanceTwoPoints) \ No newline at end of file