I am having issues with incorrect math output for my program. I have to write a program that takes in two coordinates (for a triangle) and then prints the area and perimeter. This program also needs to include a menu. So option 1 would allow the user to enter four numbers (for the coordinates), option 2 would print the perimeter based on the coordinates entered, and option 3 would print the area.
When I enter the coordinates, the perimeter and area options give me really weird numbers in scientific notation and both the area and perimeter options return the same number. Can someone find an issue in my code that may be causing this?
Note: My program is split up into 3 files, so I apologize in advance if it's too long.
Thanks for your reply. I know a triangle should have three sets of coordinates but my instructor only requires two for this assignment (even though that's not a triangle). But I will try to rework my math.
We also have an astronomy thread nearby that opens up opportunities for that too, but I digress @lastchance.
Given the OP reply and our mutual shock, I can now only imagine that the unspoken but nevertheless vital vertex is at the origin.
So @OP you will have x0 = 0.0, y0 = 0.0 This will make some of the calculations much easier for you to do but you'll need to take them carefully one at a time. The first step is to work out the length of each side.
Afetr that you'll need to check the triangle inequality to make sure you have a triangle.
If it is a triangle, the perimeter then the are follows. They don't need to be stored, getPerimeter and getArea are the way to go.
http://www.math-only-math.com/area-and-perimeter.html has a formula for the area of a triangle given the length of the 3 sides
Ah @kemort, the area of a triangle on the surface of a sphere is much more complicated (and the angles don't add up to 180 degrees either.) But yes, I had noticed the astronomy thread!
For the area of a triangle (on a flat piece of paper) you can also use (without any square roots to find the side lengths):
A = 0.5 * abs ( (x1-x0)(y2-y0) - (x2-x0)(y1-y0) )
If (x0,y0) happens to equal (0,0) then this simplifies to
A = 0.5 * abs( x1.y2 - x2.y1 )
Quickest way to prove it is the vector area of a triangle (1/2) axb where a and b are the side vectors.