arc.centroid()函數用於計算圓弧中心線的中點。使用(startAngle + endAngle)/2和(innerRadius + outerRadius)/2計算生成的中點。
用法:
arc.centroid(arguments);
參數:該函數接受如上所述和以下描述的單個參數。
- arguments:這些是任意參數。
返回值:此函數返回包含點的數組。
範例1:
HTML
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport"
content="width=device-width,
initial-scale=1.0"/>
<!--Fetching from CDN of D3.js -->
<script src=
"https://d3js.org/d3.v6.min.js">
</script>
</head>
<body>
<script>
// Creating an arc
var arc = d3.arc()
.innerRadius(40)
.outerRadius(45)
.startAngle(10)
.endAngle(8);
// arc.centroid function
console.log(arc.centroid());
</script>
</body>
</html>
輸出:
範例2:
HTML
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport"
content="width=device-width,
initial-scale=1.0"/>
<!--Fetching from CDN of D3.js -->
<script src=
"https://d3js.org/d3.v6.min.js">
</script>
</head>
<body>
<script>
// Creating an arc
var arc = d3.arc()
.innerRadius(40)
.outerRadius(45)
.startAngle(0)
.endAngle(8);
// arc.centroid function
console.log("Change in start and end angle");
console.log("will change the centroid");
console.log(arc.centroid());
</script>
</body>
</html>
輸出:
相關用法
- d3.js d3.mean()用法及代碼示例
- p5.js pan()用法及代碼示例
- PHP ord()用法及代碼示例
- PHP Ds\Map get()用法及代碼示例
- PHP Ds\Set xor()用法及代碼示例
- d3.js d3.min()用法及代碼示例
- d3.js dsv()用法及代碼示例
- p5.js nfs()用法及代碼示例
- d3.js now()用法及代碼示例
- p5.js nf()用法及代碼示例
- d3.js d3.map.set()用法及代碼示例
- p5.js nfc()用法及代碼示例
- p5.js nfp()用法及代碼示例
- PHP Ds\Set contains()用法及代碼示例
- d3.js d3.hsl()用法及代碼示例
- p5.js value()用法及代碼示例
注:本文由純淨天空篩選整理自tarun007大神的英文原創作品 D3.js arc.centroid() Function。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。