If it is, you claim that f + g = h (as best as you can tell) and deal with the degenerate case.\), then \(\angle DEG\cong \angle FEG\). You then check whether the sum of f and g is somewhere between h - epsilon and h + epsilon – or put another way, whether the absolute value of f + g - h is less than or equal to epsilon. In those cases, if you want to catch degenerate triangles, what you usually do is pick an "epsilon" value (some very small value relative to the numbers you're dealing with) that represents the maximum amount of roundoff you're willing to tolerate. But when checking the "not a triangle" condition, it's relatively easy to set up a situation where adding the two sides rounds off (because of the vicissitudes of floating-point arithmetic in the CPU) to something that's very close to, but not quite exactly, the third side. There are three specific types of isosceles. For checking the equilateral/isosceles/scalene conditions, you're fine because the user is directly entering in the floating-point numbers and you're not manipulating them, so there's no chance for you to introduce error. An isosceles triangle is a triangle where two of the sides are of equal length and the angles opposite of the equal sides are also equal to each other. When comparing floating-point numbers, you should always be careful to consider whether a strict equality is going to get you what you want.You could probably reasonably rule out lengths of 0 as well, to eliminate the possibility of degenerate triangles that just look like line segments or points. Checking to make sure the sides are non-negative is a great idea.Make sure you use the one the professor asks for. In C++, double and float are not the same thing.Looking at why this inequality has to hold: if the sum of two sides was exactly equal to the third side's length, you'd have a "degenerate" triangle where sides f and g could only lay on top of h! If they added up to less, the two sides could connect to the endpoints of h but then would never meet at a third point! You can test this yourself by cutting lengths of string or strips of paper and trying it out. However, it may be just as convenient for you to check all three cases. If you're dealing with isosceles or scalene triangles, you technically only need to check the smaller two sides against the largest side, and if it's true for them, it's true for the other two cases as well (why?). If you're dealing with equilateral triangles, you automatically know this condition is met (why?). :-)įor the sides to make a proper triangle, for each pair of sides (I'll call them f and g), they must add up to greater than the third side's length (I'll call it h). A triangle has three sides and three angles The three angles always add to 180° Equilateral, Isosceles and Scalene There are three special names given to triangles that tell how many sides (or angles) are equal. One of the important properties of isosceles triangles is that their base angles are always congruent. In the triangle ABC (given above), AB and AC are the two legs of the isosceles triangle. The angle made by the two legs is called the vertex angle. Legs: The two equal sides of an isosceles triangle are known as ‘legs’. The angles between the base and the legs are called base angles. Don't be afraid to put on your math hat here and go wandering in, a little logic isn't a bad thing for a poli sci student to endure every now and then. The congruent sides of the isosceles triangle are called the legs. But I'll give you some help with the "not a triangle" condition. It just involves a simple comparison of side lengths you don't have to go as far as angles. The logic falls out neatly from the definition of these different types of triangles, which as the professor notes, is information readily obtained from Wikipedia. Our professor has not covered this topic in class. ![]() I currently have: //lab eleven program code on trianglesĮlse if(aside=bside || aside=cside || bside=cside)īut I need help with the if and else if statements to determine the type triangle. You may use the same values as in the example. Print the resulting triangle type to the console.Įnsure your Triangle detector works by running it 5 times as in the example above. Use a series of nested if / else statements to determine if the triangle having side-lengths as set by the user is an EQUILATERAL, ISOSCELES, or SCALENE triangle. Repeat the last 2 steps twice more, once for each of the remaining 2 sides of the triangle. ![]() Set the user’s input to the variable you created representing the first side of the triangle. Prompt the user to input a value for the first side, then I need help with the following code that requires me to:ĭeclare 3 double type variables, each representing one of three sides of a triangle.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |