除了JavaScript以外,还有更多的数学问题...我有这段代码可以从较小的圆中创建一个半圆,但是我不确定如何旋转它,以便半圆从圆的顶部开始而不是从侧面开始(将其向左旋转45º)。

var items = 9;

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

  var x = 200 + 50 * Math.cos(1.1 * Math.PI * i / items);
  var y = 100 + 50 * Math.sin(1.1 * Math.PI * i / items);

  $("body").append("<div class='point' style='left:" + x + "px;top:" + y + "px'></div>");

}
.point {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: white;
  border: 1px solid black;
  position: absolute;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>


Current Output
Desired Output

谢谢!

最佳答案

我相信这就是您想要的:

var items = 8;

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

    var x = 200 + 50 * Math.cos(Math.PI * i / items);
    var y = 100 + 50 * Math.sin(Math.PI * i / items);

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

}
#location {

    width:200px;
    height:200px;
    /* border-radius:100px; */
    background: black;
    position:relative;
    left:200px;
    top:100px;

}

#center {
  transform: rotateZ(-80deg);
}

.point {

    width:8px;
    height:8px;
    border-radius:50%;
    background: white;
    border: 1px solid black;
    position:absolute;

}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div id="center"></div>

07-25 23:09
查看更多