/**
* *
* Global license : *
* Microsoft Public Licence
*
* author Manuel Dahmen <ibiiztera.it@gmail.com>
*
Creation time 17-sept.-2014
*
**
*/
package nurbs;
import be.ibiiztera.md.pmatrix.pushmatrix.Camera;
import be.ibiiztera.md.pmatrix.pushmatrix.Point3D;
import be.ibiiztera.md.pmatrix.pushmatrix.nurbs.SurfaceParametriquePolynomialeBezier;
import be.ibiiztera.md.pmatrix.test.pushmatrix.newtest.TestObjet;
/**
*
* @author Manuel Dahmen <ibiiztera.it@gmail.com>
*/
public class SurfaceBezier extends TestObjet {
@Override
public void testScene() {
Point3D[][] p = new Point3D[9][9];
int m = 0;
for (int i = -4; i <= 4; i++) {
int n = 0;
for (int j = -4; j <= 4; j++) {
p[m][n] = new Point3D(i, j, 0);
n++;
}
m++;
}
SurfaceParametriquePolynomialeBezier surfaceParametriquePolynomialeBezier = new SurfaceParametriquePolynomialeBezier(p);
scene().add(surfaceParametriquePolynomialeBezier);
scene().cameraActive(new Camera(Point3D.Z.mult(-10), Point3D.O0));
}
public static void main(String[] arg) {
SurfaceBezier t1 = new SurfaceBezier();
t1.setGenerate(GENERATE_IMAGE|GENERATE_MODEL);
t1.loop(false);
new Thread(t1).start();
}
}
/***
Global license :
Microsoft Public Licence
author Manuel Dahmen <ibiiztera.it@gmail.com>
Creation time 17-sept.-2014
***/
Il me semble que le bug doit être dans ce fragment:
package be.ibiiztera.md.pmatrix.pushmatrix.nurbs;
import be.ibiiztera.md.pmatrix.pushmatrix.Point3D;
/**
*
* @author Manuel Dahmen <ibiiztera.it@gmail.com>
*/
public class SurfaceParametriquePolynomialeBezier extends ParametrizedSurface
{
protected final Point3D[][] coefficients;
protected int power1, power2;
public SurfaceParametriquePolynomialeBezier(Point3D [][] coefficients)
{
this.coefficients = coefficients;
power1 = coefficients.length;
power2 = coefficients[0].length;
}
protected double factorielle(int n)
{
double sum = 1;
for(int i=1 ; i<=n; i++)
sum *= i;
return sum;
}
public double B(int i, int n, double t)
{
return
factorielle(n)/factorielle(i)/factorielle(n-i)
*Math.pow(t, i)*Math.pow(1-t, n-i);
}
@Override
public Point3D calculerPoint3D(double u, double v) {
Point3D sum = Point3D.O0;
for(int i=0;i<power1; i++)
for(int j=0;j<power2; j++)
sum = sum.plus(coefficients[i][j].mult(B(i, power1, u)*B(j, power2, v)));
return sum;
}
@Override
public Point3D calculerVitesse3D(double u, double v) {
throw new UnsupportedOperationException(« pas encore implanté »);
}
}
Laisser un commentaire