最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - What is the difference between alphaTarget and alphaMin? - Stack Overflow

programmeradmin6浏览0评论

The description from the API is confusing. I expect target to be the value where the simulation stops ticking, but what target does is not defined in the API. Also alpha itself is not defined in the API but I found that on another website: /

An important aspect of simulations is alpha. alpha is a number between 0 and 1 and defines how far the simulation has progressed. When a simulation starts alpha is set to 1 and this value slowly decays, based on the alphaDecay rate, until it reaches the alphaTarget of the simulation. Once the alpha value is less than the alphaTarget, the simulation es to a halt. The alphaTarget by default is set to 0.1

Now for the official API:

simulation.alphaMin([min])

If min is specified, sets the minimum alpha to the specified number in the range [0,1] and returns this simulation. If min is not specified, returns the current minimum alpha value, which defaults to 0.001. The simulation’s internal timer stops when the current alpha is less than the minimum alpha. The default alpha decay rate of ~0.0228 corresponds to 300 iterations.

simulation.alphaTarget([target])

If target is specified, sets the current target alpha to the specified number in the range [0,1] and returns this simulation. If target is not specified, returns the current target alpha value, which defaults to 0.

The description from the API is confusing. I expect target to be the value where the simulation stops ticking, but what target does is not defined in the API. Also alpha itself is not defined in the API but I found that on another website: https://roshansanthosh.wordpress./2016/09/25/forces-in-d3-js-v4/

An important aspect of simulations is alpha. alpha is a number between 0 and 1 and defines how far the simulation has progressed. When a simulation starts alpha is set to 1 and this value slowly decays, based on the alphaDecay rate, until it reaches the alphaTarget of the simulation. Once the alpha value is less than the alphaTarget, the simulation es to a halt. The alphaTarget by default is set to 0.1

Now for the official API:

simulation.alphaMin([min])

If min is specified, sets the minimum alpha to the specified number in the range [0,1] and returns this simulation. If min is not specified, returns the current minimum alpha value, which defaults to 0.001. The simulation’s internal timer stops when the current alpha is less than the minimum alpha. The default alpha decay rate of ~0.0228 corresponds to 300 iterations.

simulation.alphaTarget([target])

If target is specified, sets the current target alpha to the specified number in the range [0,1] and returns this simulation. If target is not specified, returns the current target alpha value, which defaults to 0.

Share Improve this question edited Apr 24, 2019 at 5:42 Gerardo Furtado 102k9 gold badges128 silver badges176 bronze badges asked Sep 26, 2017 at 12:05 PlumpiePlumpie 4662 gold badges7 silver badges28 bronze badges 2
  • OK I figured most of it out by just logging alpha to the console: alphaMin sets the alpha-level where the simulation will stop running (tick-events stop happening), alphaTarget redefines where the alpha will eventually end up (the asymptote), so instead of slowly going to 0 it will slowly go to 0.2. Lord only knows what the purpose of the alphaTarget is. – Plumpie Commented Sep 26, 2017 at 13:21
  • 3 alphaTarget has a few cool uses, if you are dragging for example, you can set the alphaTarget to have the simulation run continuously at a specific rate of change to have smooth motion. – Andrew Commented Sep 26, 2017 at 15:25
Add a ment  | 

1 Answer 1

Reset to default 15

Concepts like alphaMin and alphaTarget are, indeed, quite hard to understand, and on top of that they are not very well explained in the docs.

You got it almost right in your ment:

OK I figured most of it out by just logging alpha to the console: alphaMin sets the alpha-level where the simulation will stop running (tick-events stop happening), alphaTarget redefines where the alpha will eventually end up (the asymptote), so instead of slowly going to 0 it will slowly go to 0.2. Lord only knows what the purpose of the alphaTarget is. (emphasis mine)

So, the missing part for you to understand these concepts is to understand "what [is] the purpose of the alphaTarget". And that's quite simple:

As you know, alphaMin sets the minimum alpha, which will be responsible for stopping the simulation when the current alpha falls below it. So, if we set the alphaTarget to a value above the alphaMin, the simulation never stops.

For instance, have a look at this forked bl.ocks, where I set the alphaTarget to 0.8: https://bl.ocks/GerardoFurtado/91368069a381009d30468aa9774c0de3/e58316dfdb05b68b02e5692c26b360c990da0383

As you can see, that simulation will run forever.

Of course, even with a high alphaTarget value the simulation will stop if the alphaMin is higher, but in a quite unpleasant and abrupt way. For instance, alphaMin = 0.991 and alphaTarget = 0.99: https://blockbuilder/GerardoFurtado/72961f5e63eb75b6202d9e24dc25e67b

发布评论

评论列表(0)

  1. 暂无评论