www.vorhilfe.de
- Förderverein -
Der Förderverein.

Gemeinnütziger Verein zur Finanzierung des Projekts Vorhilfe.de.
Hallo Gast!einloggen | registrieren ]
Startseite · Mitglieder · Impressum
Forenbaum
^ Forenbaum
Status VH e.V.
  Status Vereinsforum

Gezeigt werden alle Foren bis zur Tiefe 2

Navigation
 Startseite...
 Suchen
 Impressum
Das Projekt
Server und Internetanbindung werden durch Spenden finanziert.
Organisiert wird das Projekt von unserem Koordinatorenteam.
Hunderte Mitglieder helfen ehrenamtlich in unseren moderierten Foren.
Anbieter der Seite ist der gemeinnützige Verein "Vorhilfe.de e.V.".
Partnerseiten
Weitere Fächer:

Open Source FunktionenplotterFunkyPlot: Kostenloser und quelloffener Funktionenplotter für Linux und andere Betriebssysteme
Forum "Computergraphik" - Bézier-Algorithmus
Bézier-Algorithmus < Computergraphik < Praktische Inform. < Hochschule < Informatik < Vorhilfe
Ansicht: [ geschachtelt ] | ^ Forum "Computergraphik"  | ^^ Alle Foren  | ^ Forenbaum  | Materialien

Bézier-Algorithmus: Korrektur/Tipps
Status: (Frage) beantwortet Status 
Datum: 11:46 Sa 09.03.2013
Autor: ponysteffi

Aufgabe
Umsetzung des Bézier-Algorithmus in Java

Ich habe mich am Algorithmus versucht (Abwandlung von http://www.codeproject.com/Articles/25237/Bezier-Curves-Made-Simple), kann mir jemand helfen wo die Umsetzung fehlerhaft ist?


public void calculateCurve() {

int cpts = 17;
int npts = controlPoints.size()/2;
System.out.println("ntps =" + npts);
    int icount, jcount;
    double step, t;

    // Calculate points on curve

    icount = 0;
    t = 0;
    step = (double)1.0 / (cpts - 1);
System.out.println("Step =" + step);
    for (int i1 = 0; i1 != cpts; i1++) {
        if ((1.0 - t) < 5e-6)
            t = 1.0;

        jcount = 0;
        curvePoints.add(icount, new Point2D.Float((int) 0, (int) 0));
        for (int i = 0; i != npts; i++)  {
            double basis = bernsteinPolynomial(i , npts - 1, t);
            System.out.println("Basis = " +basis);
            double x =  curvePoints.get(icount).getX() + basis * controlPoints.get(jcount).getX();
            double y = curvePoints.get(icount).getY() + basis * controlPoints.get(jcount).getY();
            System.out.println("x = " + x  + " y = " + y);
            curvePoints.add(icount, new Point2D.Float((int) x, (int) y));
            jcount++;
        }

        icount++;
        t += step;
    }
    
    
    
}

/**
* Calculates the Bernstein polynomial
* @param i index of the current control point [0..n]
* @param n number of control points - 1
* @param t parameter value [0..1]
* @return polynomial value
*/
private static double bernsteinPolynomial(int i, int n, double t) {
return Math.pow(t, i) * Math.pow(1 - t, n - i) * factorial(n) / (factorial(i) * factorial(n - i));
}


/**
* Calculates the factorial of n
* @param n
* @return n!
*/
private static double factorial(int n) {
if(n == 0 | n == 1){
return 1.0;
}
double res = 1;
for(int i=2; i<=n; i++){
res*=i;
}
return res;
}

        
Bezug
Bézier-Algorithmus: Antwort
Status: (Antwort) fertig Status 
Datum: 17:06 Sa 09.03.2013
Autor: MathePower

Hallo ponysteffi,

> Umsetzung des Bézier-Algorithmus in Java
>  Ich habe mich am Algorithmus versucht (Abwandlung von
> http://www.codeproject.com/Articles/25237/Bezier-Curves-Made-Simple),
> kann mir jemand helfen wo die Umsetzung fehlerhaft ist?
>  
>
> public void calculateCurve() {
>  
> int cpts = 17;
>   int npts = controlPoints.size()/2;
>   System.out.println("ntps =" + npts);
>   int icount, jcount;
>   double step, t;
>  
> // Calculate points on curve
>  
> icount = 0;
>   t = 0;
>   step = (double)1.0 / (cpts - 1);
>   System.out.println("Step =" + step);
>   for (int i1 = 0; i1 != cpts; i1++) {
> if ((1.0 - t) < 5e-6)
> t = 1.0;
>  
> jcount = 0;
>   curvePoints.add(icount, new Point2D.Float((int) 0, (int)
> 0));
>   for (int i = 0; i != npts; i++)  {
>   double basis = bernsteinPolynomial(i , npts - 1, t);
>   System.out.println("Basis = " +basis);
>   double x =  curvePoints.get(icount).getX() + basis *
> controlPoints.get(jcount).getX();
>   double y = curvePoints.get(icount).getY() + basis *
> controlPoints.get(jcount).getY();
>   System.out.println("x = " + x  + " y = " + y);
>   curvePoints.add(icount, new Point2D.Float((int) x, (int)
> y));
>   jcount++;
>   }
>  
> icount++;
>   t += step;
>   }
>  


Nach dem angegebenen Link zum Algorithmus werden
in der äusseren Schleife 2 Punkte erzeugt, die dann in
der inneren Schleife auch verändert werden.

Damit sind auch die Zählvariablen
icount, jcount entsprechend zu verändern.


>
>
> }
>  
> /**
>   * Calculates the Bernstein polynomial
> * @param i index of the current control point [0..n]
>   * @param n number of control points - 1
>   * @param t parameter value [0..1]
>   * @return polynomial value
>   */
>   private static double bernsteinPolynomial(int i, int n,
> double t) {
>   return Math.pow(t, i) * Math.pow(1 - t, n - i) *
> factorial(n) / (factorial(i) * factorial(n - i));
>   }
>  
>
> /**
>   * Calculates the factorial of n
>   * @param n
>   * @return n!
>   */
>   private static double factorial(int n) {
>   if(n == 0 | n == 1){
>   return 1.0;
>   }
>   double res = 1;
>   for(int i=2; i<=n; i++){
>   res*=i;
>   }
>   return res;
>   }  


Den Programmcode kannst Du zwischen
[mm]\[[code\]][/mm] und [mm]\[[/code\]][/mm] reinschreiben.


Gruss
MathePower


Bezug
                
Bezug
Bézier-Algorithmus: Mitteilung
Status: (Mitteilung) Reaktion unnötig Status 
Datum: 09:52 So 10.03.2013
Autor: ponysteffi

Hallo MathePower

Es ist mir bewusst, dass beim angegebenen Algorithmus mit abwechselnden X und Y Punkten gearbeitet wird. Ich habe aber einen Array mit Point2D-Werten und habe den Code darum angepasst...

Gruss


Bezug
        
Bezug
Bézier-Algorithmus: Antwort
Status: (Antwort) fertig Status 
Datum: 14:35 So 10.03.2013
Autor: MathePower

Hallo ponysteffi,

> Umsetzung des Bézier-Algorithmus in Java
>  Ich habe mich am Algorithmus versucht (Abwandlung von
> http://www.codeproject.com/Articles/25237/Bezier-Curves-Made-Simple),
> kann mir jemand helfen wo die Umsetzung fehlerhaft ist?
>  
>
> public void calculateCurve() {
>  
> int cpts = 17;
>   int npts = controlPoints.size()/2;
>   System.out.println("ntps =" + npts);
>   int icount, jcount;
>   double step, t;
>  
> // Calculate points on curve
>  
> icount = 0;
>   t = 0;
>   step = (double)1.0 / (cpts - 1);
>   System.out.println("Step =" + step);
>   for (int i1 = 0; i1 != cpts; i1++) {
> if ((1.0 - t) < 5e-6)
> t = 1.0;
>  


> jcount = 0;
>   curvePoints.add(icount, new Point2D.Float((int) 0, (int)
> 0));
>   for (int i = 0; i != npts; i++)  {
>   double basis = bernsteinPolynomial(i , npts - 1, t);
>   System.out.println("Basis = " +basis);
>   double x =  curvePoints.get(icount).getX() + basis *
> controlPoints.get(jcount).getX();
>   double y = curvePoints.get(icount).getY() + basis *
> controlPoints.get(jcount).getY();
>   System.out.println("x = " + x  + " y = " + y);
>   curvePoints.add(icount, new Point2D.Float((int) x, (int)
> y));


Hier ist doch die entsprechende set-Methode zu verwenden,
da der Punkt an dieser Stelle bereits existiert.


>   jcount++;
>   }
>  
> icount++;
>   t += step;
>   }
>  
>
>
> }
>  
> /**
>   * Calculates the Bernstein polynomial
> * @param i index of the current control point [0..n]
>   * @param n number of control points - 1
>   * @param t parameter value [0..1]
>   * @return polynomial value
>   */
>   private static double bernsteinPolynomial(int i, int n,
> double t) {
>   return Math.pow(t, i) * Math.pow(1 - t, n - i) *
> factorial(n) / (factorial(i) * factorial(n - i));
>   }
>  
>
> /**
>   * Calculates the factorial of n
>   * @param n
>   * @return n!
>   */
>   private static double factorial(int n) {
>   if(n == 0 | n == 1){
>   return 1.0;
>   }
>   double res = 1;
>   for(int i=2; i<=n; i++){
>   res*=i;
>   }
>   return res;
>   }  


Gruss
MathePower

Bezug
                
Bezug
Bézier-Algorithmus: Frage (beantwortet)
Status: (Frage) beantwortet Status 
Datum: 15:55 So 10.03.2013
Autor: ponysteffi

Auch mit der Set-Methode wird leider keine schlaue Kurve berechnet...

Bezug
                        
Bezug
Bézier-Algorithmus: Antwort
Status: (Antwort) fertig Status 
Datum: 16:19 So 10.03.2013
Autor: MathePower

Hallo ponysteffi,

> Auch mit der Set-Methode wird leider keine schlaue Kurve
> berechnet...


Dann poste die Klassen zu denen die Objekte
curvePoints und controlPoints gehören.


Gruss
MathePower

Bezug
Ansicht: [ geschachtelt ] | ^ Forum "Computergraphik"  | ^^ Alle Foren  | ^ Forenbaum  | Materialien


^ Seitenanfang ^
ev.vorhilfe.de
[ Startseite | Mitglieder | Impressum ]