关于雷达图

微信截图_20230613212020.png

使用drawPolygon和drawRegularPolygon在同一个点上绘制多边形时,两个没能重合,是这两个api的中心坐标算法不一致吗?
已邀请:

谷主

赞同来自: 如梦令初醒

你这代码写得不对。多边形的左边应该是本地坐标。改成:
 for (let j: number = 0; j < size; j++) {
            posArr.push(radius + radius * Math.cos(vertexRadian * j));
            posArr.push(radius + radius * Math.sin(vertexRadian * j));
        }

谷主

赞同来自:

Laya和fgui分别是什么版本

xiezuobao

赞同来自:

    /** 
     * @param size 正多边形变数 
     * @param radius 内切半径 
     * @param center 内切圆坐标
     * */
    private drawRadialBg(size: number, radius: number, center: Laya.Vector2, lineSize: number = 3,
        lineColor: string = "#BDBDBD", fillColor: string = "#3B596B"): fgui.GGraph {
        let graph: fgui.GGraph = new fgui.GGraph();
        graph.setSize(radius * 2, radius * 2);
        graph.setPivot(0.5, 0.5);
        graph.setXY(center.x, center.y);
        let posArr: number = ;
        let vertexRadian = 2 * Math.PI / size;//顶角弧度
        for (let j: number = 0; j < size; j++) {
            posArr.push(center.x + radius * Math.cos(vertexRadian * j));
            posArr.push(center.y + radius * Math.sin(vertexRadian * j));
        }
        graph.drawPolygon(lineSize, lineColor, fillColor, posArr);
        return graph;
    }
 

    private drawRadial(radius: number, center: Laya.Vector2, valueArr: number, lineSize: number = 3,
        lineColor: string = "#FF9900", fillColor: string = "#99FF33"): fgui.GGraph {
        let graph: fgui.GGraph = new fgui.GGraph();
        graph.setSize(radius * 2, radius * 2);
        graph.setPivot(0.5, 0.5);
        graph.setXY(center.x, center.y);
        graph.drawRegularPolygon(lineSize, lineColor, fillColor, valueArr.length, 0, valueArr);
        return graph;
    }
 
 
//===================

        let graph: fgui.GGraph = this.drawRadialBg(6, 150, new Laya.Vector2(200, 100));
        obj.addChild(graph);
        let graph6: fgui.GGraph = this.drawRadial(150, new Laya.Vector2(200, 100), [1, 1, 1, 1, 1, 1]);
        obj.addChild(graph6);
 

谷主

赞同来自:

好的,我测试一下

要回复问题请先登录注册