build a c++ program to read 4 letters from the user and calculate the grade point average.grade point average is calculated as folllows.(a=4, b=3, c=2, d=1, f=0)
a sample run should be as follows.
enter the grade for subject 1: A
enter the grade for subject 2: C
enter the grade for subject 3: A
enter the grade for subject 4: D
grade point average is 4+2+4+1= 11.
pls pls pls pls pls pls pls pls pls do this for me pls pls
Pls biuld a c++ program to see weather two triangles overlap or not?
How do the question and the title to your question relate?
Reply:The description doesn't match the question, so I'll just answer the question.
Two triangles overlap if any edges in triangle A intersect with any edges in triangle B. To calculate if two edges intersect you need to represent them with 2 line equations:
Line A: p = P1 + t * (P2 - P1)
Line B: p = P3 + s * (P4 - P3)
At the point of intersection these equations will be equal:
P1 + t * (P2 - P1) = P3 + s * (P4 - P3)
This is actually a simultaneous equation in the two unknowns t and s:
P1.x + t * (P2.x - P1.x) = P3.x + s * (P4.x - P3.x)
P1.y + t * (P2.y - P1.y) = P3.y + s * (P4.y - P3.y)
Rearrange this to solve the simultaneous equation and that will give you the two unknowns (when you do this you'll wind up with a division, if the denominator is 0 then the lines are parallel and therefore don't intersect). If both s and t are between 0 and 1 then the lines intersect in the valid portion of the lines and the triangles intersect each other.
Of course, there are plenty of ways to speed this algorithm up. One way is to first test the bounding boxes against each other to see if you can trivially reject the intersection.
There is one case that this wont detect and that is where a triangle completely encloses another. To detect for that plug all points in triangle A into triangle B's line equation and make sure they're all on the *right* of each edge, if this happens for any point then the triangles intersect. Do the same test of the points in B against triangle A.
Reply:Done sir.
Reply:Yes sir
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment