Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.4k views
in Technique[技术] by (71.8m points)

关于在x轴在0-100,y轴在0-100这个区域内,随机个数点,随机分布的问题?

后端返回给前端不定个数个点,并且包括点与点之间如何连线,如何在x(0,100),y(0,100)这个区域内分布得均匀一点,不要那么凌乱。

function random(min, max) {
    return Math.floor(Math.random() * (max - min)) + min   
}
var getCoord = (data) => {
        return data.map(item => {
            var x = random(0,100)
            var y = random(0,100)
            return {...item,x,y}
        })
    }

这些点的坐标是随机产生的,一旦连线就很凌乱
image.png

哪位大佬提供个思路如何才能分布得不那么凌乱?


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

不凌乱就把随机数的区域改小,在一定范围内随机呗

比如说用 index/length 划分区域,每一块区域内随机分配。


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

1.4m articles

1.4m replys

5 comments

57.0k users

...