// N차원 베지어 곡선 계산 public void nextBezierN() { int k, kn, nn, nkn; double blend, muk, munk; int n = arrPn.length - 1; initResultPoint(); muk = 1; munk = Math.pow(1 - mu, (double) n); for (k = 0; k <= n; k++) { nn = n; kn = k; nkn = n - k; blend = muk * munk; muk *= mu; munk /= (1 - mu); while (nn >= 1) { blend *= nn; nn--; if (kn > 1) { blend /= (double) kn; kn--; } if (nkn > 1) { blend /= (double) nkn; nkn--; } } resultPoint.x += arrPn[k].x * blend; resultPoint.y += arrPn[k].y * blend; resultPoint.z += arrPn[k].z * blend; } }
// 3차원 베지어 곡선 계산 public void nextBezier3() { double mum1, mum12, mu2; initResultPoint(); mu2 = mu * mu; mum1 = 1 - mu; mum12 = mum1 * mum1; resultPoint.x = p1.x * mum12 + 2 * p2.x * mum1 * mu + p3.x * mu2; resultPoint.y = p1.y * mum12 + 2 * p2.y * mum1 * mu + p3.y * mu2; resultPoint.z = p1.z * mum12 + 2 * p2.z * mum1 * mu + p3.z * mu2; }
// 4차원 베지어 곡선 계산 public void nextBezier4() { double mum1, mum13, mu3; initResultPoint(); mum1 = 1 - mu; mum13 = mum1 * mum1 * mum1; mu3 = mu * mu * mu; resultPoint.x = mum13 * p1.x + 3 * mu * mum1 * mum1 * p2.x + 3 * mu * mu * mum1 * p3.x + mu3 * p4.x; resultPoint.y = mum13 * p1.y + 3 * mu * mum1 * mum1 * p2.y + 3 * mu * mu * mum1 * p3.y + mu3 * p4.y; resultPoint.z = mum13 * p1.z + 3 * mu * mum1 * mum1 * p2.z + 3 * mu * mu * mum1 * p3.z + mu3 * p4.z; }
public void initResultPoint() { resultPoint.x = 0.0; resultPoint.y = 0.0; resultPoint.z = 0.0; }