ubisum
ubisum

Reputation: 179

Transforming the cartesian representation of a segment into polar form and viceversa

Suppose to have a segment described by its two extremes on cartesian plane, as two couples of coordinates. I need to represent such segment in "polar form", as a couple theta, d, where theta is its slope and d its distance from origin of cartesian axes.

I guess I correctly computed theta as the slope of line containing segment. On the other end, I have some doubts about d, because it seems to me that distance of origin from line containing segment is not exactly distance of segment from origin. How would you compute the couple theta, d?

One more question: suppose to have a correct couple theta, d: do you think it's possible to get back to original cartesian representation and get back to original segment's extremes?

thanks for help.

Upvotes: 1

Views: 207

Answers (1)

Edward
Edward

Reputation: 7100

If the end points of an arbitrary segment are specified as (a,b) and (c,d) in Cartesian coordinates, then expressing that in polar form would simply be a matter of expressing the two endpoints in polar form (dist, angle). In C, one might do that conversion like this:

double a,b;
dist = sqrt(pow(a,2)+pow(b,2));
angle = atan2(b, a);

Upvotes: 0

Related Questions