/* Copyright (C) 2004 - 2014 A.Vontobel  
 * Classes in drawj2d.bgd are derived from fachwerk.sourceforge.net, 2014
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * as published by the Free Software Foundation; either version 2
 * of the License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
 *
 * The license is in LICENCE-GPL.txt.
 * If not, see http://www.gnu.org/licenses/old-licenses/gpl-2.0.html.
 */

package net.sf.drawj2d.bgd;

public class clHintergrundBogen {
    private double[] zentrum = new double[2];
    private double radius;
    private final double[] sektor = new double[2]; // [startwinkel, endwinkel]
    
    clHintergrundBogen(double X, double Z, double radius, double startwinkel, double endwinkel) {
        zentrum[0] = X;
        zentrum[1] = Z;
        this.radius = radius;
        sektor[0] = startwinkel;
        sektor[1] = endwinkel;
    }

    /** Skaliert Hintergrundbogen.
     Warnung: Verzerrte Skalierung von Bögen kann nur durch geometrisch gemittelten
     Kreisbogen angenähert werden. */
    public boolean skaliere(double faktorx, double faktorz) {
        assert (Math.abs(faktorx) >= 1E-9);
        assert (Math.abs(faktorz) >= 1E-9);
        zentrum[0] = faktorx * zentrum[0];
        zentrum[1] = faktorz * zentrum[1];
        double faktor = Math.sqrt(Math.abs(faktorx * faktorz)); // geometrisches Mittel
        radius = faktor * radius;
        // Start- und Endwinkel rotieren infolge Skalierung
        if (faktorx != faktorz || faktorx < 0) {
            double startwinkel = -Math.toRadians(sektor[0]);
            startwinkel = Math.atan2(faktorz * Math.sin(startwinkel), faktorx * Math.cos(startwinkel));
            double endwinkel = -Math.toRadians(sektor[1]);
            endwinkel = Math.atan2(faktorz * Math.sin(endwinkel), faktorx * Math.cos(endwinkel));
            if (faktorx * faktorz >= 0) {
                sektor[0] = -Math.toDegrees(startwinkel);
                sektor[1] = -Math.toDegrees(endwinkel);
            }
            else {
                sektor[0] = -Math.toDegrees(endwinkel);
                sektor[1] = -Math.toDegrees(startwinkel);
            }
        }
        return true;
    }
    
    public void verschiebe(double dx, double dz) {
        zentrum[0] += dx;
        zentrum[1] += dz;   
    }

    /** Rotiert im Uhrzeigersinn.
    * @param rot Rotation im Uhrzeigersinn, in Radianten */
    public void rotiere(double rot) {
        double X = zentrum[0];
        double Z = zentrum[1];
        zentrum[0] = X * Math.cos(rot) - Z * Math.sin(rot);
        zentrum[1] = X * Math.sin(rot) + Z * Math.cos(rot);
        // Start- und Endwinkel rotieren
        sektor[0] = Math.toDegrees(Math.toRadians(sektor[0]) - rot);
        sektor[1] = Math.toDegrees(Math.toRadians(sektor[1]) - rot);
    }
    
    /** Gibt die Koordinate des Hintergrundpunktes zurück.
     */
    public double[] getZentrum() {
        return zentrum;
    }
    
    public double getRadius() {
        return radius;
    }
    
    public double[] getSektor() {
        return sektor;
    }
}

 

Ads help maintain this website.