/* Copyright (C) 2014 A.Vontobel  
 *
 * 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.cmd.statics;

import org.hecl.*;

/**
 * StatAddCmd implements the "stat.add", which 
 * returns the force vector sum and a valid application point.
 * Any force is expected in the order "x0 y0 Fx Fy".
 */

public class StatAddCmd implements Command {
    boolean debug = false;
    
    public StatAddCmd () {
    }
    
    @Override
    public Thing cmdCode(Interp interp, Thing[] argv) throws HeclException {
        assert argv.length > 0;
        if (debug) System.out.println(argv[0].toString());
        
        if (argv.length < 1+1) throw new HeclException ("Illegal nb of arguments.");
        
        clKraft[] Flist = new clKraft[argv.length - 1];
        for (int i = 1; i < argv.length; i++) {
            Thing[] currentargv = ListThing.getArray(argv[i]);
            if (currentargv.length != 4) throw new HeclException ("Illegal argument format. \"x0 y0 Fx Fy\" (all numbers) expected.");
            double Fx = NumberThing.asNumber(currentargv[2]).doubleValue();
            double Fy = NumberThing.asNumber(currentargv[3]).doubleValue();
            double x0 = NumberThing.asNumber(currentargv[0]).doubleValue();
            double y0 = NumberThing.asNumber(currentargv[1]).doubleValue();
            Flist[i-1] = new clKraft(Fx, Fy, x0, y0);
        }
        
        clResultierende res = new clResultierende();
        
        for (clKraft Fi : Flist) {
            res.add(Fi);
        }
        
        double[] R = res.F();
        double[] point = res.pkt();

        String Rxstr = StringThing.get(DoubleThing.create(R[0]));
        String Rystr = StringThing.get(DoubleThing.create(R[1]));
        String xstr = StringThing.get(DoubleThing.create(point[0]));
        String ystr = StringThing.get(DoubleThing.create(point[1]));
        String answer = xstr + " " + ystr + " " + Rxstr + " " + Rystr;
        
	return new Thing(answer);
    }
}

 

Ads help maintain this website.