找回密码
 注册
搜索
查看: 617|回复: 3

[讨论] 【请教】:函数mmi_pen_check_inside_polygon

[复制链接]
发表于 2009-9-17 22:47:51 | 显示全部楼层 |阅读模式
大体是判断触点是否在某一范围内,但不知polygon的num具体是什么作用,这一函数的算法是怎么判断的?
函数如下:
MMI_BOOL mmi_pen_check_inside_polygon(mmi_pen_polygon_area_struct *polygon, mmi_pen_point_struct pos)
{
    /*----------------------------------------------------------------*/
    /* Local Variables                                                */
    /*----------------------------------------------------------------*/
    MMI_BOOL c = MMI_FALSE;
    S16 i, j;
    S16 nPoints = polygon->num;
    mmi_pen_point_struct *outline = polygon->points;
    S16 x = pos.x;
    S16 y = pos.y;

    /*----------------------------------------------------------------*/
    /* Code Body                                                      */
    /*----------------------------------------------------------------*/
    for (i = 0, j = nPoints - 1; i < nPoints; j = i++)   //这个循环具体在干吗???[/COLOR]    {
        mmi_pen_point_struct *a = &outline;
        mmi_pen_point_struct *b = &outline[j];

        if (((a->y <= y && y < b->y) || (b->y <= y && y < a->y)) &&
            (x < (b->x - a->x) * (y - a->y) / (b->y - a->y) + a->x))
        {
            c = !c;
        }
    }
    MMI_TRACE(MMI_FW_TRC_G6_FRM_DETAIL, MMI_PEN_TRC_CHECK_INSIDE_POLYGON, pos.x, pos.y,
        outline[0].x, outline[0].y, outline[1].x, outline[1].y, outline[2].x, outline[2].y, outline[3].x, outline[3].y, c);

    return c;
}

THS……
发表于 2009-9-19 11:01:13 | 显示全部楼层
我猜测这个应该好像可能貌似是个标志,指明多边形的某个属性吧[em10][em07]
点评回复

使用道具 举报

发表于 2009-9-19 11:49:14 | 显示全部楼层
该算法利用了这样的一个心理: 只要检测点DP(Detection Point)位于多边形(polygon)内部, 那么for循环语句的第一步先粗略断定其为内点, 如果其后的n-1步都没能否定这个事实的话, 那么该点最终被确认为多边形内点.
点评回复

使用道具 举报

 楼主| 发表于 2009-9-19 16:52:50 | 显示全部楼层
谢谢楼上的回答,但还是很模糊
提示一下
该函数频繁出现在AudioPlayerMainScreen.c的mmi_audply_pen_down_hdlr中
有兴趣的可以看一下,共同学习哈
polygon的成员很简单,如下
typedef struct
{
    mmi_pen_point_struct *points;
    S16 num;
} mmi_pen_polygon_area_struct;

断点跟了N次,num应该是多边形的顶点数,一般是4,即是矩形,
会给出相应的4点坐标(如何确定就不清楚了?),
但是只有在判断左右软键时传入的pos才是触点的坐标
当判断其他位置时,传入的pos是触点坐标的与图片坐标的差值

但这一函数的算法实在没看懂,其数学原理是什么,还请达人用直白的语言简单描述一下
先谢过了
点评回复

使用道具 举报

高级模式
B Color Image Link Quote Code Smilies

本版积分规则

Archiver|手机版|小黑屋|52RD我爱研发网 ( 沪ICP备2022007804号-2 )

GMT+8, 2025-2-25 13:35 , Processed in 0.102066 second(s), 16 queries , Gzip On.

Powered by Discuz! X3.5

© 2001-2023 Discuz! Team.

快速回复 返回顶部 返回列表