Beispiel #1
0
        /// <summary>
        /// point是否在扇形范围内
        /// </summary>
        /// <param name="point"></param>
        /// <returns></returns>
        public bool ContainPoint(Vector3 point)
        {
            point.y = 0;
            Vector3 line = point - m_center;
            float   dis  = Vector3.SqrMagnitude(line) - m_radius * m_radius;

            //如果角度为0, 我们就只判断距离
            if (m_angle <= 0)
            {
                return(dis <= m_radius * m_radius);
            }

            //距离太远在圆形外
            if (dis > 0)
            {
                return(false);
            }

            float startAngle = m_centerAngle - m_angle * 0.5f;
            float endAngle   = m_centerAngle + m_angle * 0.5f;

            float targetAngle = CMathUtil.GetVec3AngleInXZ(line);

            return(targetAngle > startAngle && targetAngle < endAngle);
        }
Beispiel #2
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="pt"></param>
        /// <returns></returns>
        public bool pointInRect(Vector3 pt)
        {
            //Arectangle = 0.5⋅(yA − yC)⋅(xD−xB)+(yB−yD)⋅(xA−xC)
            //四边形面积公式
            if (m_area < 0)
            {
                m_area = 0.5f * Mathf.Abs(
                    (m_a.y - m_c.y) * (m_d.x - m_b.x) +
                    (m_b.y - m_d.y) * (m_a.x - m_c.x));
            }



            //Atriangle=0.5⋅(x1⋅(y2−y3)+x2⋅(y3−y1)+x3⋅(y1−y2))
            //三角形面积


            float abp  = GetTriangleArea(m_a, m_b, pt);
            float bcp  = GetTriangleArea(m_b, m_c, pt);
            float cdp  = GetTriangleArea(m_c, m_d, pt);
            float dap  = GetTriangleArea(m_d, m_a, pt);
            float area = abp + bcp + cdp + dap;

            return(CMathUtil.FloatEqual(area, m_area, 0.1f));
        }
Beispiel #3
0
 /// <summary>
 /// 设置扇形中心线
 /// </summary>
 /// <param name="direction"></param>
 public void SetDirection(Vector3 direction)
 {
     m_direction   = direction;
     m_direction.y = 0;
     m_centerAngle = CMathUtil.GetVec3AngleInXZ(m_direction);
 }