Write a program that prompts the user to enter three points (x1,
y1), (x2, y2), (x3, y3) of a triangle and displays its area.
The formula for computing the distance of two points (x1, y1) and (x2, y2) is
d = Math.sqrt((x2 - x1) * (x2 - x1) + (y2 - y1) * (y2 - y1));
or
d = Math.pow((x2 - x1) * (x2 - x1) + (y2 - y1) * (y2 - y1), 0.5);
The formula for computing the area of a triangle is
s = (side1 + side2 + side3) / 2.0;
area = Math.sqrt(s * (s - side1) * (s - side2) * (s - side3));
or
area = Math.pow(s * (s - side1) * (s - side2) * (s - side3), 0.5);
Here is a sample run:
Enter three points for a triangle: 1.5 -3.4 4.6 5.0 9.5 -3.4
The area of the triangle is 33.60.
Since you have not provided the language of your preference, I am providing the code in Java.
import java.util.Scanner;
public class tester {
public static double getDistance(double x1, double y1, double x2, double y2) {
return Math.sqrt((x2 - x1) * (x2 - x1) + (y2 - y1) * (y2 - y1));
}
public static void main(String[] args) {
double x1, y1, x2, y2, x3, y3;
Scanner sc = new Scanner(System.in);
System.out.print("Enter three points for a triangle: ");
x1 = sc.nextDouble();
y1 = sc.nextDouble();
x2 = sc.nextDouble();
y2 = sc.nextDouble();
x3 = sc.nextDouble();
y3 = sc.nextDouble();
double side1 = getDistance(x1, y1, x2, y2);
double side2 = getDistance(x2, y2, x3, y3);
double side3 = getDistance(x3, y3, x1, y1);
double s = (side1 + side2 + side3) / 2.0;
double area = Math.sqrt(s * (s - side1) * (s - side2) * (s - side3));
System.out.format("The area of the triangle is : %.2f", area);
}
}
Write a program that prompts the user to enter three points (x1, y1), (x2, y2), (x3,...
Must be in Python 3.6 (please have a screen shot on the code) ex 2.14 : # Enter three points for a triangle x1, y1, x2, y2, x3, y3 = eval(input("Enter three points for a triangle: ")) # Compute the length of the three sides side1 = ((x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2)) ** 0.5 side2 = ((x1 - x3) * (x1 - x3) + (y1 - y3) * (y1 -...
x1 X2 X3 Atnangle has vertices (x1y1)(X2 y2) and X3 Уз) The area of the triangle IS given by the absolute value of D where D: y1 y2 y3 Use this formula to find the area of a triangle with vertices (6,8), (8,2), and (9,6) The area is square unit(s) Enter your answer in the answer box O Type here to search
Welcome to the Triangles program Enter length 1: 3 Enter length 2: 5 Enter length 3: 5 Enter the base: 5 Enter the height: 8 --------------------- The triangle is Isosceles since it has two equal length sides. Isosceles triangle also has two equal angles The area is: 20 The permimeter is: 13 Continue? (y/n): y Enter length 1: 10 Enter length 2: 10 Enter length 3: 10 Enter the base: 10 Enter the height: 7 --------------------- The triangle is Equilateral...
The distance, d, between two points, (x1,y1)(x1,y1) and (x2,y2)(x2,y2), can be found using the formula d=√(x2−x1)^2+(y2−y1)^2. How can you rearrange the given formula to correctly find y2?
Create a UML diagram with 3 lines per class/interface including all constructors. public class Point { public double X, Y; public Point() { this(0, 0); } public Point(double newX, double newY) { X = newX; Y = newY; } public static double distance(Point A, Point B) { return Math.sqrt(Math.pow(A.X-B.X, 2) + Math.pow(A.Y-B.Y, 2)); } } public interface Polygon { public int getNumberOfSides(); public double getPerimeter(); public double getArea(); } public abstract class Simple_polygon implements Polygon{ public Point...
3) Let (x, y), (X2, y2), and (X3. Y3) be three points in R2 with X1 < x2 < X3. Suppose that y = ax + by + c is a parabola passing through the three points (x1, yı), (x2, y), and (x3, Y3). We have that a, b, and c must satisfy i = ax + bx + C V2 = ax + bx2 + c y3 = ax} + bx3 + c Let D = x X2 1....
1(a) Write a python program using a function name slope(x1, y1, x2, y2) that returns the slope of the line through the points (x1, y1) and (x2, y2). 1(b) For problem 1(a), write a python program using a function name Euclidean_dist(x1, y1, x2, y2) which will calculate and return the Euclidean distance between the points (x1, y1) and (x2, y2).
matlab 3. Filename: area2d.m The area of a triangle whose three vertices are points (x1, yı), (X2, y2), and (x3, y3) can be found using the absolute value of the following equation: A = 3 [x: (– yz) – x2\1 – yz) + x3V1 – Yz)] Write a MATLAB function area2d that calculates the area of a triangle using the following syntax: A = area2d (x,y) where x and y are vectors such that x = [X1, X2, X3] and...
Set A contains three numbers x1, x2 and x3. Set B contains four numbers y1, y2, y3 and y4. These two sets have the following characteristics: Set Mean Standard deviation A 10 2 B 45 5 Set X consists of the following eight numbers: u1 =70, u2 =7x1, u3 =7x2, u4 =7x3, u5 =2y1, u6 =2y2, u7 =2y3, u8 =2y4. Find the mean and standard deviation of the numbers in set X.
Consider the following equations: y1 = a1y2 +a2y3 +x1 +x2 +e1 (1) y2 = by1+2x3+x1+e2 (2) y3 =cy1+e3 (3) Here a1, a2, b, c are unknown parameters of interest, which are all posi- tive. x1, x2, x3 are exogenous variables (uncorrelated with y1, y2 or y3). e1, e2, e3 are error terms. (a) In equation (1), why y2,y3 are endogenous? (b) what is (are) the instrumental variable(s) for y2, y3 in equation (1)? (no need to explain why) (c) In...