d3.js畫圓弧和圓的坐標(biāo)、弧長計(jì)算方法

svg路徑畫圓的特性:(rx ry x-axis-rotation large-arc-flag sweep-flag x y)。
rx,ry: 是橢圓的兩個(gè)半軸的長度。
x-axis-rotation: 是橢圓相對于坐標(biāo)系的旋轉(zhuǎn)角度,角度數(shù)而非弧度數(shù)。
large-arc-flag: 是標(biāo)記繪制大弧(1)還是小弧(0)部分。
sweep-flag: 是標(biāo)記向順時(shí)針(1)還是逆時(shí)針(0)方向繪制。
x,y: 是圓弧終點(diǎn)的坐標(biāo)。

已知兩點(diǎn)和半徑求弧路徑。

/*
    兩點(diǎn)加半徑生成圓弧的路徑
    sweepFlag: 1順時(shí)針(從左到右),0逆時(shí)針(從右到左)
*/
function getArcPath(p1, p2, r, sweepFlag = 1) {
    let L = Math.abs(p1[0] - p2[0])
    let rotateL = -(p1[1] - p2[1])
    if (sweepFlag === 0) L = -L
    return `a${r},${r} 0 0,${sweepFlag} ${L},${rotateL}`  // 對比圓的特性
}

已知圓上兩點(diǎn)和半徑求弧長。

/*
    p1: 圓上的坐標(biāo)點(diǎn)[x,y]
    p2: 圓上的坐標(biāo)點(diǎn)[x,y]
    r: 半徑
*/
function getArcLeng(p1, p2, r) {
    // p1 p2 的距離
    let pLeng = Math.sqrt(Math.pow(p1[0] - p2[0], 2) + Math.pow(p1[1] - p2[1], 2))
    // 正弦值 一半
    let sinValue = (pLeng/2)/r
    // 反正弦 得到度數(shù)*2
    let asin = Math.asin(sinValue)*180/Math.PI*2
    let leng = Math.PI*r*asin/180
    return leng
}

已知圓上的y軸半徑和圓心求相交的x軸坐標(biāo)。

/*
    y: y坐標(biāo)
    r: 半徑
    mindPoint: 圓心坐標(biāo)
*/
function getArcX(y, r, mindPoint) {
    // x = Math.sqrt(r2 - (y - b)2) + a
    let arcMindX = Math.sqrt(Math.pow(r,2) - Math.pow(y - mindPoint[1],2)) + mindPoint[0]
    return {
        leftPoint: arcMindX - 2*(arcMindX - mindPoint[0]),
        rightPoint: arcMindX
    }
}

已知圓上的x軸半徑和圓心求y軸坐標(biāo)。

/*
    x: x坐標(biāo)
    r: 半徑
    mindPoint: 圓心坐標(biāo)
*/
function getArcY(x, r, mindPoint) {
    // (x - a)2 + (y - b)2 = r2 //弧坐標(biāo)公式 (a,b)圓心坐標(biāo)
    // y = Math.sqrt(r2 - (x - a)2) + b
    let arcMindY = Math.sqrt(Math.pow(r,2) - Math.pow(x - mindPoint[0],2)) + mindPoint[1]
    return arcMindY - 2*(arcMindY - mindPoint[1])
}
最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容