001/******************************************************************************* 002 * This software is provided as a supplement to the authors' textbooks on digital 003 * image processing published by Springer-Verlag in various languages and editions. 004 * Permission to use and distribute this software is granted under the BSD 2-Clause 005 * "Simplified" License (see http://opensource.org/licenses/BSD-2-Clause). 006 * Copyright (c) 2006-2016 Wilhelm Burger, Mark J. Burge. All rights reserved. 007 * Visit http://imagingbook.com for additional details. 008 *******************************************************************************/ 009 010package imagingbook.pub.geometry.mappings.nonlinear; 011 012import imagingbook.pub.geometry.mappings.Mapping; 013 014public class TwirlMapping extends Mapping { 015 double xc, yc, angle, rad; 016 017 public TwirlMapping (double xc, double yc, double angle, double rad, boolean inv) { 018 this.xc = xc; 019 this.yc = yc; 020 this.angle = angle; 021 this.rad = rad; 022 this.isInverseFlag = inv; 023 } 024 025 public static TwirlMapping makeInverseMapping(double xc, double yc, double angle, double rad){ 026 return new TwirlMapping(xc, yc, angle, rad, true); 027 } 028 029 public double[] applyTo (double[] xy){ 030 double x = xy[0]; 031 double y = xy[1]; 032 double dx = x - xc; 033 double dy = y - yc; 034 double d = Math.sqrt(dx*dx + dy*dy); 035 if (d < rad) { 036 double a = Math.atan2(dy,dx) + angle * (rad-d) / rad; 037 double x1 = xc + d * Math.cos(a); 038 double y1 = yc + d * Math.sin(a); 039 //pnt.setLocation(x1, y1); 040 return new double[] {x1, y1}; 041 } 042 return xy.clone(); 043 } 044} 045 046 047 048