2014-10-16 49 views
-2

我想用JS生成一个半圈的点,但不知道数学来完成这个。我会用什么公式?使用公式I可以管理。生成一系列描述javascript中弧的点?

+0

这个问题似乎是题外话,因为它是关于数学公式,而不是编程。 – Mathletics 2014-10-16 19:09:24

+0

够公平的,但它很简洁,答案正是某人寻找这种类型的东西会想要的,所以我不认为它应该被关闭。 – Joren 2014-10-16 23:04:30

回答

1

的基本公式找到一个圆上的点的x/y坐标是:

X = circleX +(circleRadius *余弦(角度))

Y = circleY +(circleRadius *正弦(角度))

凡circleX和circleY是您的圆的中心的x/y坐标

//Math functions use radians so we will need to convert degrees to radians 
 
var radPerDeg = Math.PI/180; 
 

 
function genPoint(centerX,centerY,degree,radius){ 
 
    var x = centerX + (radius * Math.cos(degree*radPerDeg)); 
 
    var y = centerY + (radius * Math.sin(degree*radPerDeg)); 
 

 
    var p = document.createElement("div"); 
 
    p.style.left = x+"px"; 
 
    p.style.top = y+"px";  
 
    document.body.appendChild(p); 
 
} 
 

 
for(var i=0; i<=180; i+=10){ 
 
    genPoint(200,100,i,50); 
 
}
div { 
 
    border-radius:5px; 
 
    width:5px; 
 
    height:5px; 
 
    background:#000; 
 
    position:absolute; 
 
}

+0

这正是我需要的,谢谢! – Joren 2014-10-16 21:01:29

0

您可以使用HTML5画布或SVG来做到这一点。 http://www.w3.org/Graphics/SVG/ 在这里你可以使用SVG https://developer.mozilla.org/en-US/docs/Web/SVG/Attribute

找到属性的列表,但使用JavaScript您的问题。 为了做到这一点与JavaScript,我认为最好的办法就是通过D3.js http://d3js.org/ 这是很好的网站,开始D3 https://github.com/mbostock/d3/wiki/SVG-Shapes

在这里,你有你的解决方案Very Simple D3: How to Draw an Arc?