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

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

问题描述

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

i have the following geometrical issue in 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.

This works in 2D and 3D.

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

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