matheraum.de
Raum für Mathematik
Offene Informations- und Nachhilfegemeinschaft

Für Schüler, Studenten, Lehrer, Mathematik-Interessierte.
Hallo Gast!einloggen | registrieren ]
Startseite · Forum · Wissen · Kurse · Mitglieder · Team · Impressum
Forenbaum
^ Forenbaum
Status Hochschulmathe
  Status Uni-Analysis
    Status Reelle Analysis
    Status UKomplx
    Status Uni-Kompl. Analysis
    Status Differentialgl.
    Status Maß/Integrat-Theorie
    Status Funktionalanalysis
    Status Transformationen
    Status UAnaSon
  Status Uni-Lin. Algebra
    Status Abbildungen
    Status ULinAGS
    Status Matrizen
    Status Determinanten
    Status Eigenwerte
    Status Skalarprodukte
    Status Moduln/Vektorraum
    Status Sonstiges
  Status Algebra+Zahlentheo.
    Status Algebra
    Status Zahlentheorie
  Status Diskrete Mathematik
    Status Diskrete Optimierung
    Status Graphentheorie
    Status Operations Research
    Status Relationen
  Status Fachdidaktik
  Status Finanz+Versicherung
    Status Uni-Finanzmathematik
    Status Uni-Versicherungsmat
  Status Logik+Mengenlehre
    Status Logik
    Status Mengenlehre
  Status Numerik
    Status Lin. Gleich.-systeme
    Status Nichtlineare Gleich.
    Status Interpol.+Approx.
    Status Integr.+Differenz.
    Status Eigenwertprobleme
    Status DGL
  Status Uni-Stochastik
    Status Kombinatorik
    Status math. Statistik
    Status Statistik (Anwend.)
    Status stoch. Analysis
    Status stoch. Prozesse
    Status Wahrscheinlichkeitstheorie
  Status Topologie+Geometrie
  Status Uni-Sonstiges

Gezeigt werden alle Foren bis zur Tiefe 2

Navigation
 Startseite...
 Neuerdings beta neu
 Forum...
 vorwissen...
 vorkurse...
 Werkzeuge...
 Nachhilfevermittlung beta...
 Online-Spiele beta
 Suchen
 Verein...
 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
StartseiteMatheForenComputergraphikBézier-Algorithmus
Foren für weitere Studienfächer findest Du auf www.vorhilfe.de z.B. Astronomie • Medizin • Elektrotechnik • Maschinenbau • Bauingenieurwesen • Jura • Psychologie • Geowissenschaften
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 ^
www.unimatheforum.de
[ Startseite | Forum | Wissen | Kurse | Mitglieder | Team | Impressum ]