/** * This method computes the base function value for the NURB curve. * @param i * the knot index * @param k * the base function degree * @param t * the knot value * @param knots * the knots' values * @return the base function value */ private static float computeBaseFunctionValue(int i, int k, float t, List<Float> knots) { if (k == 1) { return knots.get(i) <= t && t < knots.get(i + 1) ? 1.0f : 0.0f; } else { return (t - knots.get(i)) / (knots.get(i + k - 1) - knots.get(i)) * CurveAndSurfaceMath.computeBaseFunctionValue(i, k - 1, t, knots) + (knots.get(i + k) - t) / (knots.get(i + k) - knots.get(i + 1)) * CurveAndSurfaceMath.computeBaseFunctionValue(i + 1, k - 1, t, knots); } } }
Vector4f controlPoint = controlPoints.get(i).get(j); float val = controlPoint.w * CurveAndSurfaceMath.computeBaseFunctionValue(i, basisVFunctionDegree, v, knots[1]) * CurveAndSurfaceMath.computeBaseFunctionValue(j, basisUFunctionDegree, u, knots[0]); store.addLocal(controlPoint.x * val, controlPoint.y * val, controlPoint.z * val); delimeter += val;
/** * This method interpolates the data for the nurbs curve. * @param u * the u value * @param nurbSpline * the nurbs spline definition * @param store * the resulting point in 3D space */ public static void interpolateNurbs(float u, Spline nurbSpline, Vector3f store) { if (nurbSpline.getType() != SplineType.Nurb) { throw new IllegalArgumentException("Given spline is not of a NURB type!"); } List<Vector3f> controlPoints = nurbSpline.getControlPoints(); float[] weights = nurbSpline.getWeights(); List<Float> knots = nurbSpline.getKnots(); int controlPointAmount = controlPoints.size(); store.set(Vector3f.ZERO); float delimeter = 0; for (int i = 0; i < controlPointAmount; ++i) { float val = weights[i] * CurveAndSurfaceMath.computeBaseFunctionValue(i, nurbSpline.getBasisFunctionDegree(), u, knots); store.addLocal(nurbSpline.getControlPoints().get(i) .mult(val)); delimeter += val; } store.divideLocal(delimeter); }
/** * This method computes the base function value for the NURB curve. * @param i * the knot index * @param k * the base function degree * @param t * the knot value * @param knots * the knots' values * @return the base function value */ private static float computeBaseFunctionValue(int i, int k, float t, List<Float> knots) { if (k == 1) { return knots.get(i) <= t && t < knots.get(i + 1) ? 1.0f : 0.0f; } else { return (t - knots.get(i)) / (knots.get(i + k - 1) - knots.get(i)) * CurveAndSurfaceMath.computeBaseFunctionValue(i, k - 1, t, knots) + (knots.get(i + k) - t) / (knots.get(i + k) - knots.get(i + 1)) * CurveAndSurfaceMath.computeBaseFunctionValue(i + 1, k - 1, t, knots); } } }
/** * This method computes the base function value for the NURB curve. * @param i * the knot index * @param k * the base function degree * @param t * the knot value * @param knots * the knots' values * @return the base function value */ private static float computeBaseFunctionValue(int i, int k, float t, List<Float> knots) { if (k == 1) { return knots.get(i) <= t && t < knots.get(i + 1) ? 1.0f : 0.0f; } else { return (t - knots.get(i)) / (knots.get(i + k - 1) - knots.get(i)) * CurveAndSurfaceMath.computeBaseFunctionValue(i, k - 1, t, knots) + (knots.get(i + k) - t) / (knots.get(i + k) - knots.get(i + 1)) * CurveAndSurfaceMath.computeBaseFunctionValue(i + 1, k - 1, t, knots); } } }
Vector4f controlPoint = controlPoints.get(i).get(j); float val = controlPoint.w * CurveAndSurfaceMath.computeBaseFunctionValue(i, basisVFunctionDegree, v, knots[1]) * CurveAndSurfaceMath.computeBaseFunctionValue(j, basisUFunctionDegree, u, knots[0]); store.addLocal(controlPoint.x * val, controlPoint.y * val, controlPoint.z * val); delimeter += val;
Vector4f controlPoint = controlPoints.get(i).get(j); float val = controlPoint.w * CurveAndSurfaceMath.computeBaseFunctionValue(i, basisVFunctionDegree, v, knots[1]) * CurveAndSurfaceMath.computeBaseFunctionValue(j, basisUFunctionDegree, u, knots[0]); store.addLocal(controlPoint.x * val, controlPoint.y * val, controlPoint.z * val); delimeter += val;
/** * This method interpolates tha data for the nurbs curve. * @param u * the u value * @param nurbSpline * the nurbs spline definition * @param store * the resulting point in 3D space */ public static void interpolateNurbs(float u, Spline nurbSpline, Vector3f store) { if (nurbSpline.getType() != SplineType.Nurb) { throw new IllegalArgumentException("Given spline is not of a NURB type!"); } List<Vector3f> controlPoints = nurbSpline.getControlPoints(); float[] weights = nurbSpline.getWeights(); List<Float> knots = nurbSpline.getKnots(); int controlPointAmount = controlPoints.size(); store.set(Vector3f.ZERO); float delimeter = 0; for (int i = 0; i < controlPointAmount; ++i) { float val = weights[i] * CurveAndSurfaceMath.computeBaseFunctionValue(i, nurbSpline.getBasisFunctionDegree(), u, knots); store.addLocal(nurbSpline.getControlPoints().get(i) .mult(val)); delimeter += val; } store.divideLocal(delimeter); }
/** * This method interpolates the data for the nurbs curve. * @param u * the u value * @param nurbSpline * the nurbs spline definition * @param store * the resulting point in 3D space */ public static void interpolateNurbs(float u, Spline nurbSpline, Vector3f store) { if (nurbSpline.getType() != SplineType.Nurb) { throw new IllegalArgumentException("Given spline is not of a NURB type!"); } List<Vector3f> controlPoints = nurbSpline.getControlPoints(); float[] weights = nurbSpline.getWeights(); List<Float> knots = nurbSpline.getKnots(); int controlPointAmount = controlPoints.size(); store.set(Vector3f.ZERO); float delimeter = 0; for (int i = 0; i < controlPointAmount; ++i) { float val = weights[i] * CurveAndSurfaceMath.computeBaseFunctionValue(i, nurbSpline.getBasisFunctionDegree(), u, knots); store.addLocal(nurbSpline.getControlPoints().get(i) .mult(val)); delimeter += val; } store.divideLocal(delimeter); }