首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
您现在的位置: 程式碼之家 >> 編程語言 >  >> C語言 >> C >> C 語言問答

C語言輪盤纏布角度計算:數學建模與代碼實現

     編輯:C 語言問答

問題數學建模

輪盤直徑 D₀=89,布厚度 h=0.5 → 每圈直徑增加 1。
每次布前進 L=320,印花。輸入 N,輸出第 N 次停車時輪盤轉動總角度(度)。

關鍵變量

  • 第 n 圈外徑:D_n = 89 + n (n 從 0 開始)
  • 第 n 圈周長:C_n = π × D_n
  • 前 n 圈布長總和:S_n = Σ_{i=0}^{n-1} π(89+i) = π(89n + n(n-1)/2)

算法步驟

  1. 總布長 L_total = N × 320
  2. 找最大完整圈數 n 使 S_n ≤ L_total:
      解不等式:89n + n(n-1)/2 ≤ L_total/π
      n = floor( (√(177² + 8L_total/π) - 177) / 2 )
  3. 剩餘布長:rem = L_total - S_n
  4. 第 n+1 圈半徑:r = (89 + n) / 2
  5. 剩餘角度(弧度):θ_rem = rem / r
  6. 總角度:θ_total = n × 2π + θ_rem → 轉度數 × 180/π

VB 參考代碼轉 C


#include 
#include 

#define PI 3.14159265358979323846

double calculateAngle(int N) {
    double L_total = N * 320.0;
    // 求完整圈數 n
    double discriminant = 177.0 * 177.0 + 8.0 * L_total / PI;
    int n = (int)floor((sqrt(discriminant) - 177.0) / 2.0);
    
    // 前 n 圈布長
    double S_n = PI * (89.0 * n + n * (n - 1) / 2.0);
    double rem = L_total - S_n;
    
    // 第 n+1 圈半徑
    double r = (89.0 + n) / 2.0;
    double theta_rem = rem / r;  // 弧度
    
    double total_rad = n * 2.0 * PI + theta_rem;
    return total_rad * 180.0 / PI;  // 轉度
}

int main() {
    int N;
    printf("輸入 N: ");
    scanf("%d", &N);
    printf("第 %d 次轉動角度: %.2f 度\n", N, calculateAngle(N));
    return 0;
}

驗證範例

N總布長完整圈數角度(度)
13200≈ 412.3°
26401≈ 720+?°
  1. 上一篇文章:
  2. 下一篇文章:
Copyright © 程式碼之家 All Rights Reserved