2010-07-28 186 views
0

你們能幫我把這個C#代碼轉換成Objective-C嗎? 我對C#/ Visual Studio毫無頭緒!iPhone:將C#代碼轉換爲Objective-C

public static class BezierSpline 
{ 

public static void GetCurveControlPoints(Point[] knots, 
     out Point[] firstControlPoints, out Point[] secondControlPoints) 
    { 
     int n = knots.Length - 1; 

     // Calculate first Bezier control points 
     // Right hand side vector 
     double[] rhs = new double[n]; 

     // Set right hand side X values 
     for (int i = 1; i < n - 1; ++i) 
      rhs[i] = 4 * knots[i].X + 2 * knots[i + 1].X; 
     rhs[0] = knots[0].X + 2 * knots[1].X; 
     rhs[n - 1] = (8 * knots[n - 1].X + knots[n].X)/2.0; 
     // Get first control points X-values 
     double[] x = GetFirstControlPoints(rhs); 

     // Set right hand side Y values 
     for (int i = 1; i < n - 1; ++i) 
      rhs[i] = 4 * knots[i].Y + 2 * knots[i + 1].Y; 
     rhs[0] = knots[0].Y + 2 * knots[1].Y; 
     rhs[n - 1] = (8 * knots[n - 1].Y + knots[n].Y)/2.0; 
     // Get first control points Y-values 
     double[] y = GetFirstControlPoints(rhs); 

     // Fill output arrays. 
     firstControlPoints = new Point[n]; 
     secondControlPoints = new Point[n]; 
     for (int i = 0; i < n; ++i) 
     { 
      // First control point 
      firstControlPoints[i] = new Point(x[i], y[i]); 
      // Second control point 
      if (i < n - 1) 
       secondControlPoints[i] = new Point(2 * knots 
        [i + 1].X - x[i + 1], 2 * 
        knots[i + 1].Y - y[i + 1]); 
      else 
       secondControlPoints[i] = new Point((knots 
        [n].X + x[n - 1])/2, 
        (knots[n].Y + y[n - 1])/2); 
     } 
    } 

    private static double[] GetFirstControlPoints(double[] rhs) 
    { 
     int n = rhs.Length; 
     double[] x = new double[n]; // Solution vector. 
     double[] tmp = new double[n]; // Temp workspace. 

     double b = 2.0; 
     x[0] = rhs[0]/b; 
     for (int i = 1; i < n; i++) // Decomposition and forward substitution. 
     { 
      tmp[i] = 1/b; 
      b = (i < n - 1 ? 4.0 : 3.5) - tmp[i]; 
      x[i] = (rhs[i] - x[i - 1])/b; 
     } 
     for (int i = 1; i < n; i++) 
      x[n - i - 1] -= tmp[n - i] * x[n - i]; // Backsubstitution. 

     return x; 
    } 
} 

謝謝。

+0

這就是所謂的C#。它看起來相當簡單,只是亂七八糟的點/數字。 – Mau 2010-07-28 12:44:59

+0

我懷疑它與C的味道有關... – SpaceDog 2010-07-28 12:47:51

+0

你究竟在遇到什麼麻煩?這一切對我來說都很直截了當。 – JeremyP 2010-07-28 12:58:37

回答

0

double [] tmp = new double [n];

tmp是一個長度爲n的數組。每個值都沒有被顯式初始化,但是它被隱式地設置爲double類型的默認值,即0。所以tmp是一個n長度的零數組。 {0,0,0,0,... 0}