English 中文(简体)
调查结果点离瓦查稿中半核素中心的百分比?
原标题:Finding point n% away from the centre of a semicircle in Javascript?

我很抱歉说,Math实际上是我的强权。 通常,我可以坐下来,但我完全 st。

I m试图用超文本/CSS/Javascript进行静态结果筛选。

在我的接口上,我有一个半奇迹(目标的适当半球)。

我有一系列的分数(100、50、80、90名左右)。

I need to plot these points on the semicircle to be n% away from the centre, where n is the value of each score - the higher the score, the closer to the centre of the target the point will appear.

我知道我的微粒是多么广泛,并且已经处理成百分数的换算,这样,较高的数值似乎更接近中心,而较低的数值则进一步显现出来。

我可以总结一下我的头脑,把这些要点划在一条线上,从目标的核心点(x = 0, y = 目标高度)到随机的角点(即点点不会重叠)。

任何建议都得到了感谢。

最佳回答

你们是否想这样做? 如你想把圈子分成<条码>。 因此,你可能拥有这样的东西:

Edit: 法典正在对原产地进行轮值,而不是特定圈子。

var scores = [];
//...
//assume scores is an array of distances from the center of the circle
var points = [];
var interval = 2 * Math.PI / N;
var angle;
for (var i = 0; i < N; i++) {
    angle = interval * i;
    //assume (cx, cy) are the coordinates of the center of your circle
    points.push({
        x: scores[i] * Math.cos(angle) + cx,
        y: scores[i] * Math.sin(angle) + cy
    });
}

然后,你可以制定<条码>点<>。 但你认为合适。

问题回答

After much headscratching, I managed to arrive at this solution (with the help of a colleague who s much, much better at this kind of thing than me):

(arr_result是一阵列,含有ID和分数,分数为100。)

for (var i = 0; i < arr_result.length; i++){

     var angle = angleArray[i]; // this is an array of angles (randomised) - points around the edge of the semicircle

     var radius = 150; // width of the semicircle

     var deadZone = 25 // to make matters complicated, the circle has a  dead zone  in the centre which we want to discount
     var maxScore = 100
     var score = parseInt(arr_result[i][ score ], 10)

     var alpha = angle * Math.PI
     var distance = (maxScore-score)/maxScore*(radius-deadZone) + deadZone
     var x = distance * Math.sin(alpha)
     var y = radius + distance * Math.cos(alpha)

     $( #marker_  + arr_result[i][ id ], templateCode).css({ // target a specific marker and move it using jQuery
          left  : pointX,
          top : pointY
     });
 }

I ve omitted the code for generating the array of angles and randomising that array - that s only needed for presentational purposes so the markers don t overlap.

在我搬走标识(但删除了)之前,我也与各位协调者做一些令人ir的事,因为我想点站在标记的底层中心,而不是顶点。





相关问题
selected text in iframe

How to get a selected text inside a iframe. I my page i m having a iframe which is editable true. So how can i get the selected text in that iframe.

How to fire event handlers on the link using javascript

I would like to click a link in my page using javascript. I would like to Fire event handlers on the link without navigating. How can this be done? This has to work both in firefox and Internet ...

How to Add script codes before the </body> tag ASP.NET

Heres the problem, In Masterpage, the google analytics code were pasted before the end of body tag. In ASPX page, I need to generate a script (google addItem tracker) using codebehind ClientScript ...

Clipboard access using Javascript - sans Flash?

Is there a reliable way to access the client machine s clipboard using Javascript? I continue to run into permissions issues when attempting to do this. How does Google Docs do this? Do they use ...

javascript debugging question

I have a large javascript which I didn t write but I need to use it and I m slowely going trough it trying to figure out what does it do and how, I m using alert to print out what it does but now I ...

Parsing date like twitter

I ve made a little forum and I want parse the date on newest posts like twitter, you know "posted 40 minutes ago ","posted 1 hour ago"... What s the best way ? Thanx.

热门标签