iT邦幫忙

0

計算公式 非常急

  • 分享至 

  • xImage

左邊高度3700 右邊高度1900
3700-1900=1800
總長度11500
11500➗1800=6.38
斜度6.38
試問中間兩個高度多少
第一柱到第二柱之間3500
第二柱到第三柱之間3500
第三柱到第四柱之間4500

haward79 iT邦研究生 1 級 ‧ 2022-03-21 18:22:12 檢舉
你的題目我看起來有點模糊
假設 第一柱 高 1900 跟第二柱長度是 3500 斜度是 6.38
3500 / ( X-1900 ) = 6.38 請問 X = 多少
以下請類推,算法其實很多種,可以用已知高度來推下一柱的高度
長度都給了只是去算高度而已
圖片
  直播研討會
圖片
{{ item.channelVendor }} {{ item.webinarstarted }} |
{{ formatDate(item.duration) }}
直播中
2
淺水員
iT邦大師 6 級 ‧ 2022-03-21 21:44:20

可利用比例關係,我就不幫算了
比例關係

看更多先前的回應...收起先前的回應...
greenriver iT邦研究生 5 級 ‧ 2022-03-22 10:43:24 檢舉

請問,我最近在練習callback function,
如果將這個例子寫成callback function

function ans(leftHeight,rightHeight,theWidth,theLocation,fn) {
    if(!!leftHeight && !!rightHeight && leftHeight != rightHeight &&!!theWidth &&!!theLocation){
        let theHeight = Math.abs(leftHeight-rightHeight)
        let slope = theWidth/theHeight
        function fn(slope,theLocation){
            return (theLocation/slope);
        }
        return fn(slope,theLocation)
    }else{
        return '此題無解';
    }
}
let myAns = ans(3700,1900,11500,3500)
console.log(myAns);

可以怎麼優化這個function呢?感謝
(一直想不到要怎麼將function的變數,壓在三個以內)

greenriver iT邦研究生 5 級 ‧ 2022-03-22 10:46:07 檢舉

ans(左邊高度,右邊高度,總長度,由左開始算的柱子位置)

淺水員 iT邦大師 6 級 ‧ 2022-03-22 11:48:33 檢舉

閉包(Closure)的作法呢?

function ans(leftHeight, rightHeight, theWidth) {
    if(
        typeof leftHeight === 'number' &&
        typeof rightHeight === 'number' &&
        typeof theWidth === 'number' &&
        theWidth !== 0
    ) {
        return function(theLocation) {
            if(typeof theLocation!=='number') {
                throw 'theLocation 必須為 number';
            }
            return leftHeight + (rightHeight - leftHeight) / theWidth * theLocation;
        }
    }
    throw 'ans(number, number, number!=0)';
}
let myAns = ans(3700, 1900, 11500);
console.log('第二柱:' + myAns(3500));
console.log('第三柱:' + myAns(7000));
greenriver iT邦研究生 5 級 ‧ 2022-03-22 16:59:42 檢舉

淺水員
原來如此,謝謝!
想問一下,平常專案會很常用到callback function嗎?
因為我用vue寫專案,沒有用過....(可能是我自己的問題)

淺水員 iT邦大師 6 級 ‧ 2022-03-22 17:21:20 檢舉

我不知道怎麼樣叫做常用
但 callback 跟 Promise 都建議要了解
在異步處理的場合很常出現

2
海綿寶寶
iT邦大神 1 級 ‧ 2022-03-21 22:18:10

https://ithelp.ithome.com.tw/upload/images/20220321/20001787L10PgECA3w.png

3,152
2,604

附上公式跟結果
公式
結果

0
lu02kimo
iT邦新手 5 級 ‧ 2022-03-22 17:56:42

問題:
https://ithelp.ithome.com.tw/upload/images/20220322/20104753fjU4bloVHP.png

答:
https://ithelp.ithome.com.tw/upload/images/20220322/20104753ZqbovvTxNU.png

參考:
斜率計算器
https://miniwebtool.com/zh-tw/slope-calculator/?x1=2500&y1=7666.667&x2=1900&y2=11500

看是距離是平均定數,還是高度為平均定數

lu02kimo iT邦新手 5 級 ‧ 2022-03-22 18:54:59 檢舉

沒注意看題目 sor
ˊ第一柱到第二柱之間3500
第二柱到第三柱之間3500
第三柱到第四柱之間4500

我要發表回答

立即登入回答