This question is bothering me....
I have had this in my head for the longest time and i keep forgeting to ask about it. I was wondering is there a way lets say i have an angle that is 60 degrees and it bends infinitly in both directions on the screen how can i determain if an object is within this angel or the inner part of the angle?
Does you question run like this ?
Given two rays that originate at a point (a,b), determine if a point(x,y) is within the two rays, where within is defined as going counterclockwise from one ray to the next.
drawing of it is like so
....^
.../
../..(x,y)
./
o------>
(a,b)
Is this what you are asking ?
You arn''t very precise.
~V''lion
Bugle4d
Given two rays that originate at a point (a,b), determine if a point(x,y) is within the two rays, where within is defined as going counterclockwise from one ray to the next.
drawing of it is like so
....^
.../
../..(x,y)
./
o------>
(a,b)
Is this what you are asking ?
You arn''t very precise.

~V''lion
Bugle4d
~V'lionBugle4d
Let K be the point [x, y] and O[a, b], OX and OY are vectors on "axes". Compute angle between OX and OK and OY and OK. If one of these angles is bigger than your 60 (or so) degrees your point is outside otherwise its inside.
X
....^
.../
../ .K(x,y)
./
O------> Y
(a,b)
Formula:
Dot(A, B)
cos(phi) = -----------
|A||B|
|A| is magnitude.
------
Dave
X
....^
.../
../ .K(x,y)
./
O------> Y
(a,b)
Formula:
Dot(A, B)
cos(phi) = -----------
|A||B|
|A| is magnitude.
------
Dave
--------Dave[ Math Studio ] A Computer Algebra System
Erm, lol.. your forumal might be right if i could understand exactly what all these letters are what is O what is K what is A what is B what is phi suppose to be is it pi ? 3.1415926?
Dot(A, B)
cos(phi) = -----------
|A||B|
what do you mean by dot(a,b) erm im trying to implment this to a game engine so erm im kinda lost? i understand |A||B| ect but i dont know what you mean by how exactly this forumal works could u give a few defintions of each letter and like what Dot(a,B) means does it mean like point is at (a,b) cooridnate then you do the cosine of pi to get what its equal tothen you do somthign with AB? what exactly do you do? lol
Dot(A, B)
cos(phi) = -----------
|A||B|
what do you mean by dot(a,b) erm im trying to implment this to a game engine so erm im kinda lost? i understand |A||B| ect but i dont know what you mean by how exactly this forumal works could u give a few defintions of each letter and like what Dot(a,B) means does it mean like point is at (a,b) cooridnate then you do the cosine of pi to get what its equal tothen you do somthign with AB? what exactly do you do? lol
Dot is dot product. If you don''t know what dot product is you read up on vector math. Phi is just a name for an angle. I''ll try to explain what Dave007 did.
Y
....^
.../
../ .K(x,y)
./
O------> X
(a,b)
To find the angle(theta) between OX and OK you find the dot product which is Dot(OX,OK) = (x-a)*1+(y-b)*0 = x-a
Then dividing that by the magnitude of OK will give you cos(theta)
cos(theta) = (x-a)/sqrt((x-a)^2+(y-b)^2)
then take the arccos of that and you get theta. If theta is between 0 and 60 then the point(K) is inside the angle.
I hope that cleared it up.
Y
....^
.../
../ .K(x,y)
./
O------> X
(a,b)
To find the angle(theta) between OX and OK you find the dot product which is Dot(OX,OK) = (x-a)*1+(y-b)*0 = x-a
Then dividing that by the magnitude of OK will give you cos(theta)
cos(theta) = (x-a)/sqrt((x-a)^2+(y-b)^2)
then take the arccos of that and you get theta. If theta is between 0 and 60 then the point(K) is inside the angle.
I hope that cleared it up.
The difference between us and a computer is that, the computer is blindingly stupid, but it is capable of being stupid many, many million times a second.-Douglas Adams
Can you elaborate on that explaintion and possibly try to teach it to someone who has only completed intermediate algebra in highschool? It would be helpful if i could understand exactly what you are talking about .. lol
OK and OX are positional vectors, which means that OK is just a line from the origin to point K. OX is a line from the origin to some point on the x-axis. To make it easy you choose (1,0) for that point. In order to find the angle between the two lines you need to find the dot product. To get dot product you multiply the 2 x coordinates and the 2 y coordinates then add the 2 products together. Like this: x1*x2+y1*y2
Since x2 is 1 and y2 is 0 it reduces down to x1.
Knowing the dot product you can find the angle between the vectors because dot product is = |OK||OX|cos(theta) where |OK| and |OX| are the magnitudes or lengths of the vectors. |OX| is 1 and |OK| is sqrt(x1^2+y1^2). So divide the dot product by |OK| and you have cos(theta). Then you can get theta by using arccos. If theta is less than 60 degrees then the point is inside the angle. Of course since acos() returns radians youl have to convert it into degrees. To do that just multiply theta by 180/pi
Since x2 is 1 and y2 is 0 it reduces down to x1.
Knowing the dot product you can find the angle between the vectors because dot product is = |OK||OX|cos(theta) where |OK| and |OX| are the magnitudes or lengths of the vectors. |OX| is 1 and |OK| is sqrt(x1^2+y1^2). So divide the dot product by |OK| and you have cos(theta). Then you can get theta by using arccos. If theta is less than 60 degrees then the point is inside the angle. Of course since acos() returns radians youl have to convert it into degrees. To do that just multiply theta by 180/pi
The difference between us and a computer is that, the computer is blindingly stupid, but it is capable of being stupid many, many million times a second.-Douglas Adams
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement
Recommended Tutorials
Advertisement