I am trying to detect if my point (x & y) are over my ray (rayrot).

This is the best I could come up with, but it's not working. How should I do this?

Code:`if ( x > cos ( rayrot ) * y && y > sin ( rayrot ) * x )`

Printable View

- 05-27-2007QueatrixIs the point over my ray? Confusing...
I am trying to detect if my point (x & y) are over my ray (rayrot).

This is the best I could come up with, but it's not working. How should I do this?

Code:`if ( x > cos ( rayrot ) * y && y > sin ( rayrot ) * x )`

- 05-27-2007Desolation
Define "not working". Also, I'm not sure what kind of degrees cos() and sin() take in input. Euler or Radians ? Your code sounds about right if we're talking about radians.

- 05-27-2007Queatrix
Yeah, I'm using radians. "not working" as in, it compiles and runs without errors, but it doesn't accomplish what I want it to.

- 05-27-2007Desolation
Well, comparing the x coordinate to cos ( rayrot ) makes no sense to me.

- 05-27-2007OnionKnight
I don't see why you're multiplying the cos and sin values by the same coordinates you wish to compare to. You should multiply those with the radius to get the correct X and Y values.

Also, you will get an inverse result if the coordinates are negative. - 05-27-2007Desolation
Good point.

- 05-30-2007Queatrix
The radius thing doesn't work either, here is what I have:

Code:`raid = sqrt ( ( x * x ) + ( y * y ) ) ;`

if ( x > cos ( rayrot ) * raid && y > sin ( rayrot ) * raid )

- 05-30-2007JaWiB
Just a guess, and it might not be the most efficient way to solve this, but couldn't you check if the inverse tangent of y/x is greater than rayrot? Essentially, if the angle that the position vector (x,y) makes with the x axis is greater than the angle the ray makes with the x axis, then the point must be above the ray.

Of course, you'd have to be careful to make adjustments if the point or ray is not in the first quadrant. - 05-30-2007JVene
I'm not sure I understand your query.

Are you asking if the point is on the line representing the array?

Like a collision? - 05-30-2007Desolation
Did anyone say 'array' ? No. We did mention a ray though. :D

- 05-31-2007iMalc
Ray - what ray?

A Ray consists of a point and a direction, where the direction would normally be a vector. However this 'rayrot' seems to be just a single value, therefore it is just an angle.

The problem would however make sense, if you state that the ray happens to cross through (0, 0) for example (which I'll assume). However since you're using angles instead of vectors, you also need to state which direction an angle of zero points in. (I'll assume that increasing angle turns clockwise, and that zero is straight up, for now).

This would mean that a point (x, y) is on the ray if:Code:`(x * cos(rayrot) == y * sin(rayrot))`

Code:`if (fabs(x * cos(rayrot) - y * sin(rayrot) < EPSILON)`

- 05-31-2007Queatrix
Thank you iMalc, that works. :) :cool:

I was able to see if it was__over__the ray just by converting == to > or <. - 06-01-2007iMalc
Oh, I took "over" to mean "on" rather than "above".

Yes that'll do it.