Problem

Two distances are required to specify the location of a point relative to an origin in two...

Two distances are required to specify the location of a point relative to an origin in two-dimensional space (Fig. P3.6):

• The horizontal and vertical distances (x, y) in Cartesian coordinates.

• The radius and angle (r, θ) in polar coordinates.

It is relatively straightforward to compute Cartesian coordi­nates (x, y) on the basis of polar coordinates (r, θ). The reverse process is not so simple. The radius can be computed by the following formula:

If the coordinates lie within the first and fourth coordinates (i.e., x > 0), then a simple formula can be used to compute θ:

FIGURE P3.6

The difficulty arises for the other cases. The following table summarizes the possibilities:

x

y

θ

<0

>0

tan-1(y/x) + π

<0

<0

tan-1(y/x) – π

<0

=0

π

=0

>0

π /2

=0

<0

π /2

=0

=0

0

Write a well-structured M-file to calculate r and θ as a func­tion of x and y. Express the final results for θ in degrees. Test your program by evaluating the following cases:

x

y

r

6

1

0

 

 

1

1

 

 

0

1

 

 

–1

1

 

 

–1

0

 

 

–1

–1

 

 

0

0

 

 

0

–1

 

 

1

–1

 

 

Step-by-Step Solution

Request Professional Solution

Request Solution!

We need at least 10 more requests to produce the solution.

0 / 10 have requested this problem solution

The more requests, the faster the answer.

Request! (Login Required)


All students who have requested the solution will be notified once they are available.
Add your Solution
Textbook Solutions and Answers Search
Solutions For Problems in Chapter 3