1

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.

ubisum
  • 179
  • 3
  • 12
  • This seems more of a mathematics question than a StackOverflow question unless you can show some associated code. – Edward Jan 16 '15 at 13:43
  • i must translate all this into code. that's all :) – ubisum Jan 16 '15 at 14:04
  • This doesn't really make sense, as you can't convert a segment into polar form. You can, however, convert points (as in, the two endpoints of the segment) into polar form. In other words, in cartesian coordinates, you have a segment described by the endpoints `x1, y1` and `x2, y2`. Those same endpoints can be described in polar form by `r1, theta1` and `r2, theta2`. But the calculations between cartesian and polar coordinates are pretty simple, and a quick Google search would have found them in less time than it took to write up the question... – twalberg Jan 16 '15 at 18:29
  • thanks for your answers. as you can see in my question, i used "" to surround the expression POLAR FORM, since it's not suitable for segments. anyway, i'm requested to use such representation for segments for my master thesis, so i don't need to convert its extremes in polar form (this would be easy). my question is: is there a way to denote the distance of a segment from origin? thanks – ubisum Jan 19 '15 at 15:42

1 Answers1

0

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);
Edward
  • 6,964
  • 2
  • 29
  • 55