2D geometry: how to check if a point is inside an angle

时光毁灭记忆、已成空白 提交于 2021-02-06 10:53:47

问题


i have the following geometrical issue in 2D:

i have a point from which i cast an infinite angle (2D-cone) which is given by a direction and an angle. (the point and the direction form a vector and to each side half of the angle forms the 2D-cone)

now i want to check if another point in 2D is inside this cone or outside.

how can this be achieved? thanks!


回答1:


Calculate the vector from the center of the cone to the query point. Normalize the vector to be of length 1, Take the center vector of the cone and normalize this as well to the length of 1.
Now take the dot product between the vectors. The dot product between two normalized vectors is the cosinus of the angle between them. Take the arccos (acos in most languages) of the dot product and you'll get the angle. compare this angle to the cone's angle (half angle in your description). if its lower, then point in question is inside the cone.

This works in 2D and 3D.




回答2:


Calculate the angle of the direction using arctg of the direction. Substract the origin from the checked point. Calculate its angle (again via arctg of a normalized vector), and check if it lies within angle boundaries.




回答3:


I would say the best way is to project the point onto the 2D surface perpendicular to the cones direction. Then you calculate the othogonal distance between that same plane and the point. Finally, you know the width of the cone at that height, so you can see if the point is outside that width.




回答4:


Let the vector from the point of origin to the specified point makes an angle A with the normal that runs through the center. If the angle A is less than the half angle of the cone it lies inside else outside.



来源:https://stackoverflow.com/questions/1167022/2d-geometry-how-to-check-if-a-point-is-inside-an-angle

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!