我想计算一个圆圈的坐标。 我不能让它打印坐标,我不确定它是否计算它们。 我的代码:
HTML:
<p>Here is the coordinates: </p>
JS:
#screen size will use screen.width and screen.height later
var sW = 1920;
var sH = 1080;
#Two arrays with the coordinates stored in them
var XcircleCoordinates;
var YcircleCoordinates;
#rows should be rows in database. I will use php to get the information, but assume 4 for now.
var rows = 4;
#radius and center of circle.
var radius = 200;
var center = [sW/2,sH/2];
function xCord(i){
XcircleCoordinates[i] = radius*Math.cos((2.0*Math.PI*i)/rows)+center[0];
return XcircleCoordinates[i];
}
function yCord(i){
YcircleCoordinates[i] = radius*Math.sin((2.0*Math.PI*i)/rows)+center[1];
return YcircleCoordinates[i];
}
for (var i = 0; i < 10; i++){
$('p').prepend(xCord(i));
}
答案 0 :(得分:0)
您的代码语法错误很少,下面应该有效。
//screen size will use screen.width and screen.height later
var sW = 1920;
var sH = 1080;
//two arrays with the coordinates stored in them
var XcircleCoordinates = new Array();
var YcircleCoordinates = new Array();
//rows should be rows in database. I will use php to get the information, but assume 4 for now.
var rows = 4;
//radius and center of circle.
var radius = 200;
var center = [sW/2,sH/2];
function xCord(i){
XcircleCoordinates[i] = radius*Math.cos((2.0*Math.PI*i)/rows)+center[0];
return XcircleCoordinates[i];
}
function yCord(i){
YcircleCoordinates[i] = radius*Math.sin((2.0*Math.PI*i)/rows)+center[1];
return YcircleCoordinates[i];
}
for (var i = 0; i < 10; i++){
$('p').prepend(xCord(i));
}
&#13;
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<p>Here is the coordinates: </p>
&#13;