Package ch.bfh.ti.kybernetik.engine

Source Code of ch.bfh.ti.kybernetik.engine.VecMathUtils

/**
* Copyright (C) BFH www.bfh.ch 2011
* Code written by: Patrick Dobler, Marc Folly
*
* 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 3 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, see <http://www.gnu.org/licenses/>.
*/
package ch.bfh.ti.kybernetik.engine;

import javax.vecmath.Point2d;
import javax.vecmath.Vector2d;

/**
* Vector Math Utility Class
*
*/
public final class VecMathUtils {

  public static Vector2d rotateVector(Vector2d directionVector, double angle) {
    double newVecX = directionVector.getX() * Math.cos(Math.toRadians(angle)) - directionVector.getY()
        * Math.sin(Math.toRadians(angle));
    double newVecY = directionVector.getX() * Math.sin(Math.toRadians(angle)) + directionVector.getY()
        * Math.cos(Math.toRadians(angle));
    Vector2d newVec = new Vector2d(newVecX, newVecY);
    newVec.normalize();
    return newVec;
  }

  public static Point2d getScaledVectorPoint(Vector2d vector, Point2d p, double size) {
    double x = p.getX() + size * vector.getX();
    double y = p.getY() + size * vector.getY();
    return new Point2d(x, y);
  }

}
TOP

Related Classes of ch.bfh.ti.kybernetik.engine.VecMathUtils

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.