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
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 )
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.
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.
Well, comparing the x coordinate to cos ( rayrot ) makes no sense to me.
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.
Good point.
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 )
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.
I'm not sure I understand your query.
Are you asking if the point is on the line representing the array?
Like a collision?
Did anyone say 'array' ? No. We did mention a ray though. :D
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:However since floating point math isn't exact you'll need to use something like this:Code:(x * cos(rayrot) == y * sin(rayrot))
Where EPSILON is a small fraction.Code:if (fabs(x * cos(rayrot) - y * sin(rayrot) < EPSILON)
Thank you iMalc, that works. :) :cool:
I was able to see if it was over the ray just by converting == to > or <.
Oh, I took "over" to mean "on" rather than "above".
Yes that'll do it.