<< Chapter < Page Chapter >> Page >

The code in Listing 9 begins by defining a function named getAngle that accepts the signed values of the adjacent side and the opposite side of the righttriangle and returns the angle that the hypotenuse makes with the positive horizontal axis.

Then the code in Listing 9 tests the result for four different triangles situated in each of the four quadrants.

Figure 18 shows the output produced by this script.

Figure 18 . Output from the code in Listing 9.
Start Script adj = 3.00 opp = 4.00 unitsangle = 53.13 units adj = -3.00 opp = 4.00 unitsangle = 126.87 units adj = -3.00 opp = -4.00 unitsangle = 233.13 units adj = 3.00 opp = -4.00 unitsangle = -53.13 units

This is an issue that will become important when we reach the module that deals with vectors in all four quadrants.

Structure of the script

The script shown in Listing 9 begins by defining a function named getAngle . The purpose of this function is to return an angle in degrees in the correct quadrant based on the lengths of the adjacent and opposite sidesof an enclosing right triangle. As mentioned above, the returned angle is the angle that the hypotenuse makes with the positive horizontal axis.

An indeterminate result

The getAngle function calls the Math.atan method to compute the angle whose tangent is the ratio of the opposite side to the adjacent side of a righttriangle.

If the lengths of both the opposite and adjacent sides are zero, the ratio opposite/adjacent is indeterminate and the value of the angle cannot be computed. In fact there is noangle corresponding to the ratio 0/0. However, the function must either return the value of an angle, or must return some sort of flag indicating thatcomputation of the angle is not possible.

In this case, the function simply returns the value zero for the angle.

Avoiding division by zero

If the length of adjacent side is zero and the length of opposite side is not zero, the ratio opposite/adjacent is infinite. Therefore, the value of the angle cannot becomputed. However, in this case, the angle is known to be 90 degrees (for opposite greater than zero) or 270 degrees (-90 degrees, for opposite less thanzero). The getAngle function traps both of those cases and returns the correct angle in each case.

Correcting for the quadrant

The Math.atan method receives one parameter and it is either a positive or negative value. If the value is positive, the method returns an angle between 0and 90 degrees. If the value is negative, the method returns an angle between 0 and -90 degrees. Thus, the angles returned by the Math.atan method always lie inthe first or fourth quadrants.

(Actually, as I mentioned earlier, +90 degrees and -90 degrees are not possible because the tangent of +90 degrees or -90 degrees is an infinitelylarge positive or negative value. However, the method can handle angles that are very close to +90 or -90 degrees.)

A negative opposite/adjacent ratio

If the opposite/adjacent ratio is negative, this doesn't necessarily mean that the angle lies in the fourth quadrant. That negative ratio could resultfrom a positive value for opposite and a negative value for adjacent. In that case, the angle would lie in the second quadrant between 90 degrees and 180degrees.

Questions & Answers

what is the stm
Brian Reply
How we are making nano material?
what is a peer
What is meant by 'nano scale'?
What is STMs full form?
scanning tunneling microscope
how nano science is used for hydrophobicity
Do u think that Graphene and Fullrene fiber can be used to make Air Plane body structure the lightest and strongest. Rafiq
what is differents between GO and RGO?
what is Nano technology ?
Bob Reply
write examples of Nano molecule?
The nanotechnology is as new science, to scale nanometric
nanotechnology is the study, desing, synthesis, manipulation and application of materials and functional systems through control of matter at nanoscale
Is there any normative that regulates the use of silver nanoparticles?
Damian Reply
what king of growth are you checking .?
What fields keep nano created devices from performing or assimulating ? Magnetic fields ? Are do they assimilate ?
Stoney Reply
why we need to study biomolecules, molecular biology in nanotechnology?
Adin Reply
yes I'm doing my masters in nanotechnology, we are being studying all these domains as well..
what school?
biomolecules are e building blocks of every organics and inorganic materials.
anyone know any internet site where one can find nanotechnology papers?
Damian Reply
sciencedirect big data base
Introduction about quantum dots in nanotechnology
Praveena Reply
what does nano mean?
Anassong Reply
nano basically means 10^(-9). nanometer is a unit to measure length.
do you think it's worthwhile in the long term to study the effects and possibilities of nanotechnology on viral treatment?
Damian Reply
absolutely yes
how to know photocatalytic properties of tio2 nanoparticles...what to do now
Akash Reply
it is a goid question and i want to know the answer as well
characteristics of micro business
for teaching engĺish at school how nano technology help us
How can I make nanorobot?
Do somebody tell me a best nano engineering book for beginners?
s. Reply
there is no specific books for beginners but there is book called principle of nanotechnology
how can I make nanorobot?
what is fullerene does it is used to make bukky balls
Devang Reply
are you nano engineer ?
fullerene is a bucky ball aka Carbon 60 molecule. It was name by the architect Fuller. He design the geodesic dome. it resembles a soccer ball.
what is the actual application of fullerenes nowadays?
That is a great question Damian. best way to answer that question is to Google it. there are hundreds of applications for buck minister fullerenes, from medical to aerospace. you can also find plenty of research papers that will give you great detail on the potential applications of fullerenes.
Berger describes sociologists as concerned with
Mueller Reply
Got questions? Join the online conversation and get instant answers!
Jobilize.com Reply

Get the best Algebra and trigonometry course in your pocket!

Source:  OpenStax, Contemporary math applications. OpenStax CNX. Dec 15, 2014 Download for free at http://legacy.cnx.org/content/col11559/1.6
Google Play and the Google Play logo are trademarks of Google Inc.

Notification Switch

Would you like to follow the 'Contemporary math applications' conversation and receive update notifications?