2D几何:如何检查点是否在角度内 [英] 2D geometry: how to check if a point is inside an angle

查看:68
本文介绍了2D几何:如何检查点是否在角度内的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在2D中遇到以下几何问题:

i have the following geometrical issue in 2D:

i有一个点,我从该点投射一个无限的角度(2D圆锥),该角度由方向和角度给出.(点和方向形成一个向量,并且到角度的每一边的一半形成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)

现在我要检查2D的另一个点是在此圆锥体的内部还是外部.

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

如何实现?谢谢!

推荐答案

计算从圆锥体中心到查询点的向量.将向量规格化为长度1,取圆锥的中心向量,并将其规格化为1的长度.
现在取向量之间的点积.两个规范化向量之间的点积是它们之间角度的余弦值.以点积的arccos(大多数语言为 acos ),您将获得角度.将此角度与圆锥角(描述中的半角)进行比较.如果其较低,则有问题的点在圆锥体内.

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.

这适用于2D和3D.

这篇关于2D几何:如何检查点是否在角度内的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆