質問

If I have a 2D line given in polar coordinates (i.e. rho distance from the origin and theta angle from the x-axis) how can I determine which on which side of the line a point lies? Specifically, how would I take two points and determine if they are on the same side or opposite sides of this line?

Thanks!

役に立ちましたか?

解決

Such line has equation:

-x*cos(theta)+y*sin(theta)-rho=0 [1]

Distance from point (x0, y0) to this line is

Dist = -x0*cos(theta)+y0*sin(theta)-rho [2]

Important thing: sign of Dist depends on which side of the line a point lies (positive when this point and coordinate origin lie on the different sides of line, and negative otherwise).

So it is enough to calc and compare the signs of the [2] expressions for two needed points

他のヒント

Could you take both of the supplied points and calculate their angles respective to theta?

Say for the sake of argument that your 2D line ends at (3,3);

2D Line:  Coord: (3,3)
 Radius: 3 * √2
 Theta: 0.79 radians

Point 1:
 Coord: (3,4)
 Radius: 5
 Theta: Arcsin(4/5) = 0.92 radians

Point 2:
 Coord: (3,1)
 Radius: √10
 Theta: Arcsin(2/√10) = 0.68 radians

Point 1's Theta is greater than that of the 2D Line; it is on one distinct side. Point 2's is less than that of the 2D line; it is on the other side.

Hope this helps! :)

I understand you have your line given by say rho with is the intersection of your line with the x-axis and theta with is the angle between your line and the x-axis.

An equation for your line then would read

f(x) = (x-rho)*tan(theta)

To determine if a point (x0,y0) is above that line check if

f(x0) = (x0-rho)*tan(theta) > y0

To check if it is under the line check

f(x0) = (x0-rho)*tan(theta) < y0

But note that this method breaks if theta= 90°, 270°. But in that case its easy you just have to check if x0 is larger or smaller then rho.

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top