• 给定圆心和半径在圆内随机画点


    最近做智慧工地系统需要在地图做实时定位,需要对工人位置进行描绘。硬件会返回信标(蓝牙定位)的位置,由于无法获取工人在地图精确位置,

    我这里暂时打算使用信标位置为圆心,距离最近信标的距离一半作为半径,去随机画点来对位置进行绘制。

    前台采用地图采用leafletjs插件,https://leafletjs.com/。

    下面是画点的算法:

    r = R * sqrt(random())
    theta = random() * 2 * PI
    
    x = centerX + r * cos(theta)
    y = centerY + r * sin(theta)
    centerX 和centerY是圆心坐标,theta是生成的角度,R是需要画点的圆的半径,套用这个公式即可
        let x0 = targetX;
        let y0 = targetY;
        let r = radius * Math.sqrt(Math.random());
        let theta = Math.random() * 2 * Math.PI;
        targetX = x0 + r * Math.cos(theta);
        targetY = y0 + r * Math.sin(theta);

    参考:https://stackoverflow.com/questions/5837572/generate-a-random-point-within-a-circle-uniformly/50746409#50746409

  • 相关阅读:
    数据库排名函数(Rank)
    请求支付报表的测试
    DateTime详细资料转载
    sqlserver2005的安装问题
    Hdu 1398 Square Coins
    HDU 1709 The Balance
    POJ 1423 Big Number
    hdu 1106 排序
    HDU 1028 Ignatius and the Princess III
    并查集Is It A Tree?hdu 1325
  • 原文地址:https://www.cnblogs.com/reject-ant/p/10108832.html
Copyright © 2020-2023  润新知