Java tutorial
/* * Copyright (C) 2014 Tim Vaughan <tgvaughan@gmail.com> * * 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 jtrace.object.transformation; import org.apache.commons.math3.geometry.euclidean.threed.Vector3D; /** * Scale coordinate transformation. * * @author Tim Vaughan <tgvaughan@gmail.com> */ public class Scale extends Transformation { private final Vector3D scaleVec; /** * Construct new scale transformation from a vector whose components * specify scaling in each direction. * * @param scaleVec scale vector */ public Scale(Vector3D scaleVec) { this.scaleVec = scaleVec; } /** * Construct new scale transformation from individual X, Y and Z * scaling magnitudes. * * @param scaleX * @param scaleY * @param scaleZ */ public Scale(double scaleX, double scaleY, double scaleZ) { this.scaleVec = new Vector3D(scaleX, scaleY, scaleZ); } /** * Construct new scale transformation that scales an object uniformly * in all directions. * * @param scale scale factor */ public Scale(double scale) { this.scaleVec = new Vector3D(scale, scale, scale); } @Override public Vector3D apply(Vector3D vec) { return new Vector3D(vec.getX() * scaleVec.getX(), vec.getY() * scaleVec.getY(), vec.getZ() * scaleVec.getZ()); } @Override public Vector3D applyInverse(Vector3D vec) { return new Vector3D(vec.getX() / scaleVec.getX(), vec.getY() / scaleVec.getY(), vec.getZ() / scaleVec.getZ()); } }