繁体   English   中英

我正在尝试在正方形周围绘制坐标

[英]I am trying to plot coordinates around a square

我试图以编程方式在一个正方形周围绘制坐标,这是硬编码来显示我所追求的。

http://jsfiddle.net/zwkny/

// amount of chairs
var aoc = 4;
// table width
var tw = 200;
// table height
var th = 200;

// chair width height
var cwh = 60 / 2;

var space = tw * 4 / aoc;

var left = [-30,100,-30,-160];
var top = [-160,-30,100,-30];

// straing point
var sp = 12;

for(var i=0; i<aoc; i++){


    var x = cwh + space * i / aoc;
    console.log(x);
    //var y = space / 2 - cwh * i;

    $("#center").append("<div class='chair' style='left:"+left[i]+"px;top:"+top[i]+"px;'>"+i+"</div>");

}

数学绝对不是我的强项,只是想我会在这里发帖,看看是否有人可以帮助我指出正确的方向,如果我明白了,我会继续前进并更新???

我需要用这种方式来代表站在大广场周围的小圆圈的人,但会有随机数量的人,而且他们都需要等距。

我昨天发布了关于圆形对象的同一篇文章,现在我在正方形上,我只是无法理解数学,任何帮助。

很抱歉,这已被否决,只是想我会更新一篇将所有这些放在一起的帖子http://devsforrest.com/116/plot-positions-around-shapes-with-javascript希望它可以帮助其他人

var x,y;

// amount of chairs
var totalChairs = 12;
// square size
var squareSize = 200;
var chairSize = 20;

for(var i=0; i<totalChairs; i++){

var angle = 2*Math.PI * i/totalChairs;

if (angle > Math.PI/4 && angle <= Math.PI* 3/4){
    x = (squareSize/2) / Math.tan(angle);
    y = -squareSize/2;
} else if (angle > Math.PI* 3/4 && angle <= Math.PI* 5/4){
    x = -squareSize/2;
    y = (squareSize/2) * Math.tan(angle);
} else if (angle > Math.PI* 5/4 && angle <= Math.PI* 7/4){
    x = -(squareSize/2) / Math.tan(angle);
    y = -squareSize/2 + squareSize;
} else {
    x = -squareSize/2 + squareSize;
    y = -(squareSize/2) * Math.tan(angle);
}

x -= chairSize/2;
y -= chairSize/2;

$("#center").append("<div class='chair' style='left:"+x+"px;top:"+y+"px;'></div>");
}

演示

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM