List of usage examples for java.lang Math tan
@HotSpotIntrinsicCandidate public static double tan(double a)
From source file:com.example.SmartBoard.DrawingView.java
public double gradient(int startX, int startY, int stopX, int stopY) { double dy = stopY - startY; double dx = stopX - startX; System.out.println("Gradient of temp line: " + Math.round((dx / dy) * 100.0) / 100.0); double slopeAngle = Math.toDegrees(Math.tan(Math.round((dx / dy) * 100.0) / 100.0)); System.out.println("Degrees:" + slopeAngle); return Math.round((dx / dy) * 100.0) / 100.0; }
From source file:org.deegree.tools.rendering.InteractiveWPVS.java
private ViewParams getViewParams(TerrainRenderingManager demRenderer) { // // setup viewer position and direction // // Point3d eye = new Point3d( 1169.4413, 989.9026, 331.31174 ); // // Point3d eye = new Point3d( 15927.5, 7689, 300 ); ////from w ww. j a v a 2 s .c o m // // Vector3d viewDirection = new Vector3d( 0.72272307, 0.64145917, -0.25741702 ); // // Point3d lookingAt = new Point3d( viewDirection ); // // lookingAt.add( eye ); // // Vector3d viewerUp = new Vector3d( 0.2185852, 0.14120139, 0.96556276 ); // // // // Point3d eye = new Point3d( 12962.94836753434, 12593.593984246898, 90.38167030764276 ); // // Point3d lookingAt = new Point3d( 12962.613589134678, 12594.53064243064, 90.48460169230239 ); // // Vector3d viewerUp = new Vector3d( 0.017654201204610157, -0.10298316020337722, 0.9945408808038575 ); // // // looking up the godesberger hill // // Point3d eye = new Point3d( 13451.07327279907, 11069.148746358578, 102.0725860674174 ); // // Point3d lookingAt = new Point3d( 13450.82937390088, 11070.108252492108, 102.21351621742897 ); // // Vector3d viewerUp = new Vector3d( 0.06727614458805162, -0.12823156824233176, 0.9894742800958647 ); // Point3d eye = new Point3d( 17986.5718025168, 10445.807745848066, 29013.44152491993 ); // Point3d lookingAt = new Point3d( 17986.5314521542, 10445.81549881379, 29012.4423694065 ); // Vector3d viewerUp = new Vector3d( -0.0042550244648288235, 0.9999738721136294, 0.007931932463392117 ); // hochwasser blick // Point3d eye = new Point3d( 12540.065339366225, 14825.06184789524, 405.8445763856689 ); // Point3d lookingAt = new Point3d( 11778.0, 14865.0, 50.0 ); // Vector3d viewerUp = new Vector3d( -0.42203907810090174, 0.022118130853929614, 0.9063077870366498 ); // ls_ns_gebiet // Point3d eye = new Point3d( 7911.181456483806, 11214.239820576904, 298.4662832984199 ); // Point3d lookingAt = new Point3d( 7992.0, 12138.0, 50.0 ); // Vector3d viewerUp = new Vector3d( 0.022557566113149727, 0.2578341604962995, 0.9659258262890682 ); // umgebungs // Point3d eye = new Point3d( 11646.815747933482, 18449.506280218528, 212.34068114402103 ); // Point3d lookingAt = new Point3d( 11429.0, 18087.0, 50.0 ); // Vector3d viewerUp = new Vector3d( -0.1845731388432743, -0.3071812879698955, 0.9335804264972021 ); // jens // Point3d eye = new Point3d( 10913.308304137812, 15021.543377732793, 90.34890557577096 ); // Point3d lookingAt = new Point3d( 10914.25310107993, 15021.218113244397, 90.30938658346824 ); // Vector3d viewerUp = new Vector3d( 0.030261091918976406, -0.03347475349449462, 0.9989813347577329 ); // Point3d eye = new Point3d( -73047.70146472409, 38512.120946986484, 26970.205157368593 ); // Point3d lookingAt = new Point3d( -73046.78120268782, 38511.863489770185, 26969.910482010924 ); // Vector3d viewerUp = new Vector3d( 0.2747903722504608, -0.11093253999688812, 0.9550833591306462 ); // Point3d eye = new Point3d( 11795.310126271357, 14458.153190013969, 128.14202719026218 ); // Point3d lookingAt = new Point3d( 11795.526694264807, 14459.094383967173, 127.88269680896333 ); // Vector3d viewerUp = new Vector3d( 0.06763746981420082, 0.2505311057936102, 0.9657428942047335 ); // // sunposition // Point3d eye = new Point3d( 0, 0, 7 ); // Point3d lookingAt = new Point3d( 0, 0, 0 ); // Vector3d viewerUp = new Vector3d( 0, 1, 0 ); // Point3d eye = new Point3d( 14863.581689508377, 14874.257693700007, 146.73991301323542 ); // Point3d lookingAt = new Point3d( 14864.08371028227, 14873.40329772973, 146.8740124858517 ); // Vector3d viewerUp = new Vector3d( -0.0579411289423698, 0.12147962354586098, 0.9909013707932913 ); // Point3d eye = new Point3d( 17183.96902170159, 11104.651411049092, 5252.299959766186 ); // Point3d lookingAt = new Point3d( 17183.87383467913, 11104.540544537771, 5251.310693347357 ); // Vector3d viewerUp = new Vector3d( 0.005618138084521037, -0.9938227673681405, 0.1108365624924782 ); // schloss // Point3d eye = new Point3d( 9215.695465194443, 15321.819352516042, 177.70466056621308 ); // Point3d lookingAt = new Point3d( 9215.868711190713, 15322.726799941856, 177.32187473293513 ); // Vector3d viewerUp = new Vector3d( 0.08839715708976609, 0.37276722064380496, 0.9237047914955354 ); // rhein // Point3d eye = new Point3d( 13925.753788033839, 14431.125891954574, 85.04428646818577 ); // Point3d lookingAt = new Point3d( 13926.097992769744, 14430.235130354195, 84.74752583894274 ); // Vector3d viewerUp = new Vector3d( 0.09598128880808184, -0.28103511759282995, 0.9548857810638757 ); // tree_posttower // Point3d eye = new Point3d( 12402.045997461932, 14793.69142817672, 70.4937199211793 ); // Point3d lookingAt = new Point3d( 12401.10002391475, 14793.382817636224, 70.39425343271608 ); // Vector3d viewerUp = new Vector3d( -0.1033479271492392, -0.0037871342018632754, 0.9946380565655442 ); // Point3d eye = new Point3d( 6448.260268219342, 17363.50304721038, 84.29050865858129 ); // Point3d lookingAt = new Point3d( 6447.634642666272, 17364.28204533543, 84.33239646721954 ); // Vector3d viewerUp = new Vector3d( 0.06425052852314768, -0.002059566706843565, 0.9979316749003633 ); // Point3d eye = new Point3d( 350, -127, 23.7 ); // Point3d lookingAt = new Point3d( 349.37437444693, -126.221001874950, 23.65811219136174 ); // Vector3d viewerUp = new Vector3d( 0.06425052852314768, -0.002059566706843565, 0.9979316749003633 ); // Point3d eye = new Point3d( 6442.004012688637, 17371.293028460885, 84.7093867449643 ); // Point3d lookingAt = new Point3d( 6441.378387135567, 17372.072026585935, 84.75127455360256 ); // Vector3d viewerUp = new Vector3d( 0.06425052852314768, -0.002059566706843565, 0.9979316749003633 ); // essen gebude // Point3d eye = new Point3d( 5441.872284653714, 7803.240170850542, 150.8541731262849 ); // Point3d lookingAt = new Point3d( 5441.621465393425, 7804.178715235103, 150.61705683228917 ); // Vector3d viewerUp = new Vector3d( 0.030150645228390737, 0.2524015253189707, 0.9671527328239826 ); // demo // Point3d eye = new Point3d( 7751.4274632595325, 7738.632168131135, 1700.8178651653407 ); // Point3d lookingAt = new Point3d( 7751.506737376979, 7739.419748747671, 1700.2067740209447 ); // Vector3d viewerUp = new Vector3d( -0.08199978679939689, 0.6160949046469247, 0.7833920496359404 ); // Point3d eye = new Point3d( 4842.663403926125, -21159.654750781716, 24123.268156063317 ); // Point3d lookingAt = new Point3d( 4842.742678043572, -21158.86717016518, 24122.65706491892 ); // Vector3d viewerUp = new Vector3d( -0.081999.78679939689, 0.6160949046469247, 0.7833920496359404 ); // Point3d eye = new Point3d( 13360.610583075291, 13759.692891781559, 8636.598222159204 ); // Point3d lookingAt = new Point3d( 13360.078832161853, 13759.276659426903, 8635.860664301814 ); // Vector3d viewerUp = new Vector3d( -0.7073708715804196, -0.2605954677793352, 0.6570513314895419 ); // Point3d eye = new Point3d( 6081.839091011266, 384.75124442199444, 6432.359365945068 ); // Point3d lookingAt = new Point3d( 6081.859440809533, 385.502735808828, 6431.699936963884 ); // Vector3d viewerUp = new Vector3d( -0.006707700408040963, 0.6596533401191206, 0.7515400705382526 ); // Kennedy // Point3d eye = new Point3d( 10394.591904069532, 17177.24388643706, 82.62293305712367 ); // Point3d lookingAt = new Point3d( 10394.961152650601, 17176.37017540717, 82.30625574245802 ); // Vector3d viewerUp = new Vector3d( 0.12756699054896722, -0.2898805092310912, 0.9485230378278534 ); // Point3d eye = new Point3d( 10394.591904069532, 17177.24388643706, 82.62293305712367 ); // Point3d lookingAt = new Point3d( 10394.961152650601, 17176.37017540717, 82.30625574245802 ); // Vector3d viewerUp = new Vector3d( 0.12756699054896722, -0.2898805092310912, 0.9485230378278534 ); // start a position that works for any other datasets (not Bonn) as well // Point3d eye = new Point3d( 0.0, 0.0, 500.0 ); // Point3d lookingAt = new Point3d( 0.0, 0.0, 0.0 ); // Vector3d viewerUp = new Vector3d( 0, 1, 0 ); Point3d eye = new Point3d(200, 200, 200); Point3d lookingAt = new Point3d(200, 200, 40); Vector3d viewerUp = new Vector3d(0, 1, 0); // Point3d eye = new Point3d( 10048.734288083613, 16641.184387034107, 102.67907642130088 ); // Point3d lookingAt = new Point3d( 10049.187423499783, 16642.04973827599, 102.89316874434968 ); // Vector3d viewerUp = new Vector3d( -0.12084130245951936, -0.17831934773102942, 0.9765242392509327 ); // Point3d eye = new Point3d( -32.39931707896916, 159.80418924642078, 1126.912059107212 ); // Point3d lookingAt = new Point3d( -32.214625131242, 159.68821181918537, 1125.9361297445957 ); // Vector3d viewerUp = new Vector3d( 0.043593521862963565, -0.9910685786306717, 0.12602649444650582 ); // Point3d eye = new Point3d( 16384.0, 16384.0, 23449.175586768335 ); // Point3d lookingAt = new Point3d( 16384.0, 16384.0, 23295.975589820093 ); // Vector3d viewerUp = new Vector3d( 0.0, 1.0, 0.0 ); // Point3d eye = new Point3d( 275.9620120805319, 64.46718597043534, 562.4719914099325 ); // Point3d lookingAt = new Point3d( 275.53842374511527, 64.61744308424116, 561.5786853471244 ); // Vector3d viewerUp = new Vector3d( -0.8988362258828301, 0.05280297809393711, 0.43509227130010486 ); // Point3d eye = new Point3d( 12918.670266734358, 11638.312310974536, 150.9617994096138 ); // Point3d lookingAt = new Point3d( 12918.923183515637, 11637.442084650263, 150.53902376427538 ); // Vector3d viewerUp = new Vector3d( 0.0768278457638342, -0.4175378808700864, 0.9054057654741021 ); // demRenderer = null; // geglttet? // Point3d eye = new Point3d( 7510.179944980607, 18132.55247159876, 68.67045685404854 ); // Point3d lookingAt = new Point3d( 7511.084219286393, 18132.97794378385, 68.63494066607761 ); // Vector3d viewerUp = new Vector3d( 0.027791438877521564, 0.024351414382101418, 0.9993170890876871 ); // b9 // Point3d eye = new Point3d( 10979.19258508588, 14968.466515333152, 64.72044690627314 ); // Point3d lookingAt = new Point3d( 10979.980566257613, 14967.850816271703, 64.72102890882154 ); // Vector3d viewerUp = new Vector3d( -0.013955210675769197, -0.016915050429668607, 0.9997595376708944 ); // Point3d eye = new Point3d( 9828.47264469345, 16798.85145159197, 60.203111000265814 ); // Point3d lookingAt = new Point3d( 9827.530665218446, 16799.169395749544, 60.09547187476404 ); // Vector3d viewerUp = new Vector3d( -0.09913125830807487, 0.04286879256498191, 0.994150521928221 ); // Point3d eye = new Point3d( 15576.6342518542, 12838.569167080923, 68.48134435085872 ); // Point3d lookingAt = new Point3d( 15576.117083773124, 12839.42435008561, 68.44671481997439 ); // Vector3d viewerUp = new Vector3d( -0.06343873856618466, 0.0020477656389633015, 0.9979836336858363 ); // Point3d eye = new Point3d( 12812.052257831021, 14217.479020702382, 107.09873254245474 ); // Point3d lookingAt = new Point3d( 12811.188477648411, 14217.920063628097, 106.85508334010474 ); // Vector3d viewerUp = new Vector3d( -0.22985946417393577, 0.08539437677143473, 0.9694701785744898 ); // Point3d eye = new Point3d( 12981.026537448855, 14614.67522876718, 64.11014757850944 ); // Point3d lookingAt = new Point3d( 12981.038842815053, 14614.578292510932, 63.11493305882678 ); // Vector3d viewerUp = new Vector3d( -0.9531604427744198, 0.29967690949927844, -0.04097462925758576 ); // Point3d eye = new Point3d( 12981.149591110829, 14613.705866204698, 54.15800238168214 ); // Point3d lookingAt = new Point3d( 12981.161896477026, 14613.60892994845, 53.162787861999476 ); // Vector3d viewerUp = new Vector3d( -0.9531604427744198, 0.29967690949927844, -0.04097462925758576 ); // Point3d eye = new Point3d( 15194.79953395015, 14758.685598863745, 260.46604235461416 ); // Point3d lookingAt = new Point3d( 15193.928403030075, 14758.526682033795, 260.00141738622966 ); // Vector3d viewerUp = new Vector3d( -0.46922710289487696, -0.009549895584917189, 0.8830258916945521 ); // Point3d eye = new Point3d( 14044.001468902079, 14493.412095321868, 99.7017835888749 ); // Point3d lookingAt = new Point3d( 14043.100411829999, 14493.217441627952, 99.31421928156796 ); // Vector3d viewerUp = new Vector3d( -0.38859083784627274, -0.034487121403220806, 0.9207647903775463 ); // Point3d eye = new Point3d( 13941.009894736511, 14468.932309482483, 54.79817692426634 ); // Point3d lookingAt = new Point3d( 13940.629520838034, 14468.899319115404, 53.873932728700424 ); // Vector3d viewerUp = new Vector3d( -0.9095971676519867, -0.16730620974684152, 0.3803177944553526 ); // Point3d eye = new Point3d( 13830.390906966933, 14466.7982625299, 52.331671222522104 ); // Point3d lookingAt = new Point3d( 13829.983666405678, 14466.903710390307, 51.42445797636429 ); // Vector3d viewerUp = new Vector3d( -0.8982101223665114, 0.13370044237873424, 0.4187394987169722 ); // Point3d eye = new Point3d( 11672.849103687942, 14869.854300744528, 69.884234719344 ); // Point3d lookingAt = new Point3d( 11671.965328114737, 14870.006960868699, 69.44192756058229 ); // Vector3d viewerUp = new Vector3d( -0.4447948753649359, 0.01934610579968591, 0.8954235015003251 ); // Point3d eye = new Point3d( 11608.37185230881, 14960.25622251627, 57.303409872107316 ); // Point3d lookingAt = new Point3d( 11607.966165915617, 14960.942471044413, 56.69968683295827 ); // Vector3d viewerUp = new Vector3d( -0.49208113043558477, 0.3926383915255517, 0.7769757104112581 ); // Point3d eye = new Point3d( 11640.826763764217, 14905.356340264812, 105.60125300402316 ); // Point3d lookingAt = new Point3d( 11640.421077371024, 14906.042588792956, 104.99752996487413 ); // Vector3d viewerUp = new Vector3d( -0.49208113043558477, 0.3926383915255517, 0.7769757104112581 ); // eye = new Point3d( 302.89945876629815, 32478.042855379656, 1107.8712218394253 ); // lookingAt = new Point3d( 302.8243522721566, 32477.936366469246, 1106.8797486292488 ); // viewerUp = new Vector3d( -0.012344764703222063, 0.9943046401331957, -0.10585787355701011 ); // // eye = new Point3d( 255.80779269279031, 32411.27445849423, 486.2189150965908 ); // lookingAt = new Point3d( 255.73268619864876, 32411.16796958382, 485.2274418864143 ); // viewerUp = new Vector3d( -0.012344764703222063, 0.9943046401331957, -0.10585787355701011 ); // // eye = new Point3d( 10620.468935048752, 14985.997719715537, 71.66828874932546 ); // lookingAt = new Point3d( 10620.490821833564, 14985.32548833627, 70.92827122157445 ); // viewerUp = new Vector3d( 0.14028570064737583, -0.7308065630552575, 0.6680132405792482 ); double fovy = 45.0; if (demRenderer != null && eye.x == 200 && eye.y == 200 && eye.z == 200) { RenderFragmentManager fragmentManager = demRenderer.getFragmentManager(); if (fragmentManager != null) { MultiresolutionMesh multiresolutionMesh = fragmentManager.getMultiresolutionMesh(); if (multiresolutionMesh != null) { double[][] bBox = multiresolutionMesh.getBBox(); if (bBox != null) { double centerX = bBox[0][0] + ((bBox[1][0] - bBox[0][0]) * 0.5f); double centerY = bBox[0][1] + ((bBox[1][1] - bBox[0][1]) * 0.5f); double centerZ = bBox[0][2] + ((bBox[1][2] - bBox[0][2]) * 0.5f); double eyeZ = Math.max(centerX, centerY) / Math.tan(Math.toRadians(fovy * 0.5)); lookingAt = new Point3d(centerX, centerY, centerZ); eye = new Point3d(centerX, centerY, eyeZ); } } } } // texture error // Point3d eye = new Point3d( 4773.823341206398, 31098.005203681878, 10435.788368373765 ); // Point3d lookingAt = new Point3d( 4774.131456607485, 31097.242049024728, 10435.220336799908 ); // Vector3d viewerUp = new Vector3d( 0.22472638841595236, -0.5217978426441787, 0.8229368516243384 ); return new ViewParams(eye, lookingAt, viewerUp, fovy, zNear, zFar); }
From source file:joshuatee.wx.USWXOGLRadarActivity.java
@Override public void onLongPress(MotionEvent event) { x = event.getX();/* w ww . j a v a 2 s . com*/ //y=0.0f; y = event.getY() - statusBarHeight - actionBarHeight; x_middle = screen_width / 2; y_middle = (screen_height - statusBarHeight - actionBarHeight) / 2; diff_x = density * (x_middle - x) / mScaleFactor; diff_y = density * (y_middle - y) / mScaleFactor; x_str = preferences.getString("RID_" + rid1 + "_X", "0.00"); y_str = preferences.getString("RID_" + rid1 + "_Y", "0.00"); //Float center_x = 0.0f; //Float center_y = 0.0f; try { center_x = Float.parseFloat(x_str); center_y = Float.parseFloat(y_str); } catch (Exception e) { } ppd = OGLR.one_degree_scale_factor; new_x = center_y + ((OGLR.mPositionX) / mScaleFactor + diff_x) / ppd; test2 = 180 / Math.PI * Math.log(Math.tan(Math.PI / 4 + center_x * (Math.PI / 180) / 2)); new_y = (float) test2 + ((-OGLR.mPositionY) / mScaleFactor + diff_y) / ppd; new_y = (float) (180 / Math.PI * (2 * Math.atan(Math.exp(new_y * Math.PI / 180)) - Math.PI / 2)); rid_tmp = UtilityLocation.GetNearestRid(getBaseContext(), Float.toString(new_y), Float.toString(new_x * -1)); if (!rid1.equals(rid_tmp)) RIDMapSwitch(rid_tmp); }
From source file:au.org.ala.biocache.web.WMSController.java
private double[] transformBbox4326To900913(double long1, double lat1, double long2, double lat2) { return new double[] { 6378137.0 * long1 * Math.PI / 180.0, 6378137.0 * Math.log(Math.tan(Math.PI / 4.0 + lat1 * Math.PI / 360.0)), 6378137.0 * long2 * Math.PI / 180.0, 6378137.0 * Math.log(Math.tan(Math.PI / 4.0 + lat2 * Math.PI / 360.0)) }; }
From source file:uk.ac.diamond.scisoft.analysis.dataset.Maths.java
/** * tan - evaluate the tangent function on each element of the dataset * @param a/* w ww .j a v a2s. c o m*/ * @return dataset */ @SuppressWarnings("cast") public static AbstractDataset tan(final AbstractDataset a) { final int isize; final IndexIterator it = a.getIterator(); AbstractDataset ds; final int dt = a.getDtype(); switch (dt) { case AbstractDataset.INT8: ds = AbstractDataset.zeros(a, AbstractDataset.FLOAT32); final byte[] i8data = ((ByteDataset) a).data; final float[] oi8data = ((FloatDataset) ds).getData(); for (int i = 0; it.hasNext();) { final byte ix = i8data[it.index]; float ox; ox = (float) (Math.tan(ix)); oi8data[i++] = ox; } break; case AbstractDataset.INT16: ds = AbstractDataset.zeros(a, AbstractDataset.FLOAT32); final short[] i16data = ((ShortDataset) a).data; final float[] oi16data = ((FloatDataset) ds).getData(); for (int i = 0; it.hasNext();) { final short ix = i16data[it.index]; float ox; ox = (float) (Math.tan(ix)); oi16data[i++] = ox; } break; case AbstractDataset.INT32: ds = AbstractDataset.zeros(a, AbstractDataset.FLOAT64); final int[] i32data = ((IntegerDataset) a).data; final double[] oi32data = ((DoubleDataset) ds).getData(); for (int i = 0; it.hasNext();) { final int ix = i32data[it.index]; double ox; ox = (double) (Math.tan(ix)); oi32data[i++] = ox; } break; case AbstractDataset.INT64: ds = AbstractDataset.zeros(a, AbstractDataset.FLOAT64); final long[] i64data = ((LongDataset) a).data; final double[] oi64data = ((DoubleDataset) ds).getData(); for (int i = 0; it.hasNext();) { final long ix = i64data[it.index]; double ox; ox = (double) (Math.tan(ix)); oi64data[i++] = ox; } break; case AbstractDataset.ARRAYINT8: ds = AbstractDataset.zeros(a, AbstractDataset.ARRAYFLOAT32); isize = a.getElementsPerItem(); final byte[] ai8data = ((CompoundByteDataset) a).data; final float[] oai8data = ((CompoundFloatDataset) ds).getData(); for (int i = 0; it.hasNext();) { for (int j = 0; j < isize; j++) { final byte ix = ai8data[it.index + j]; float ox; ox = (float) (Math.tan(ix)); oai8data[i++] = ox; } } break; case AbstractDataset.ARRAYINT16: ds = AbstractDataset.zeros(a, AbstractDataset.ARRAYFLOAT32); isize = a.getElementsPerItem(); final short[] ai16data = ((CompoundShortDataset) a).data; final float[] oai16data = ((CompoundFloatDataset) ds).getData(); for (int i = 0; it.hasNext();) { for (int j = 0; j < isize; j++) { final short ix = ai16data[it.index + j]; float ox; ox = (float) (Math.tan(ix)); oai16data[i++] = ox; } } break; case AbstractDataset.ARRAYINT32: ds = AbstractDataset.zeros(a, AbstractDataset.ARRAYFLOAT64); isize = a.getElementsPerItem(); final int[] ai32data = ((CompoundIntegerDataset) a).data; final double[] oai32data = ((CompoundDoubleDataset) ds).getData(); for (int i = 0; it.hasNext();) { for (int j = 0; j < isize; j++) { final int ix = ai32data[it.index + j]; double ox; ox = (double) (Math.tan(ix)); oai32data[i++] = ox; } } break; case AbstractDataset.ARRAYINT64: ds = AbstractDataset.zeros(a, AbstractDataset.ARRAYFLOAT64); isize = a.getElementsPerItem(); final long[] ai64data = ((CompoundLongDataset) a).data; final double[] oai64data = ((CompoundDoubleDataset) ds).getData(); for (int i = 0; it.hasNext();) { for (int j = 0; j < isize; j++) { final long ix = ai64data[it.index + j]; double ox; ox = (double) (Math.tan(ix)); oai64data[i++] = ox; } } break; case AbstractDataset.FLOAT32: ds = AbstractDataset.zeros(a, AbstractDataset.FLOAT32); final float[] f32data = ((FloatDataset) a).data; final float[] of32data = ((FloatDataset) ds).getData(); for (int i = 0; it.hasNext();) { final float ix = f32data[it.index]; float ox; ox = (float) (Math.tan(ix)); of32data[i++] = ox; } break; case AbstractDataset.FLOAT64: ds = AbstractDataset.zeros(a, AbstractDataset.FLOAT64); final double[] f64data = ((DoubleDataset) a).data; final double[] of64data = ((DoubleDataset) ds).getData(); for (int i = 0; it.hasNext();) { final double ix = f64data[it.index]; double ox; ox = (double) (Math.tan(ix)); of64data[i++] = ox; } break; case AbstractDataset.ARRAYFLOAT32: ds = AbstractDataset.zeros(a, AbstractDataset.ARRAYFLOAT32); isize = a.getElementsPerItem(); final float[] af32data = ((CompoundFloatDataset) a).data; final float[] oaf32data = ((CompoundFloatDataset) ds).getData(); for (int i = 0; it.hasNext();) { for (int j = 0; j < isize; j++) { final float ix = af32data[it.index + j]; float ox; ox = (float) (Math.tan(ix)); oaf32data[i++] = ox; } } break; case AbstractDataset.ARRAYFLOAT64: ds = AbstractDataset.zeros(a, AbstractDataset.ARRAYFLOAT64); isize = a.getElementsPerItem(); final double[] af64data = ((CompoundDoubleDataset) a).data; final double[] oaf64data = ((CompoundDoubleDataset) ds).getData(); for (int i = 0; it.hasNext();) { for (int j = 0; j < isize; j++) { final double ix = af64data[it.index + j]; double ox; ox = (double) (Math.tan(ix)); oaf64data[i++] = ox; } } break; case AbstractDataset.COMPLEX64: ds = AbstractDataset.zeros(a, AbstractDataset.COMPLEX64); final float[] c64data = ((ComplexFloatDataset) a).data; final float[] oc64data = ((ComplexFloatDataset) ds).getData(); for (int i = 0; it.hasNext();) { final float ix = c64data[it.index]; final float iy = c64data[it.index + 1]; float x; float y; float tf; float ox; float oy; x = (float) (2. * ix); y = (float) (2. * iy); tf = (float) (1. / (Math.cos(x) + Math.cosh(y))); ox = (float) (tf * Math.sin(x)); oy = (float) (tf * Math.sinh(y)); oc64data[i++] = ox; oc64data[i++] = oy; } break; case AbstractDataset.COMPLEX128: ds = AbstractDataset.zeros(a, AbstractDataset.COMPLEX128); final double[] c128data = ((ComplexDoubleDataset) a).data; final double[] oc128data = ((ComplexDoubleDataset) ds).getData(); for (int i = 0; it.hasNext();) { final double ix = c128data[it.index]; final double iy = c128data[it.index + 1]; double x; double y; double tf; double ox; double oy; x = (double) (2. * ix); y = (double) (2. * iy); tf = (double) (1. / (Math.cos(x) + Math.cosh(y))); ox = (double) (tf * Math.sin(x)); oy = (double) (tf * Math.sinh(y)); oc128data[i++] = ox; oc128data[i++] = oy; } break; default: throw new IllegalArgumentException( "tan supports integer, compound integer, real, compound real, complex datasets only"); } ds.setName(a.getName()); addFunctionName(ds, "tan"); return ds; }
From source file:com.zoffcc.applications.zanavi.Navit.java
public static int transform_from_geo_lat(double lat) { /* ZZ GEO TRANS ZZ */ int ret = (int) ((Math.log(Math.tan((Math.PI / 4f) + lat * M_PI_div_360)) * __EARTH_RADIUS__) * __GEO_ACCURACY_FACTOR__);/*from ww w . j a va2 s .com*/ return ret; }
From source file:org.eclipse.january.dataset.GeneratedMaths.java
/** * tan - evaluate the tangent function on each element of the dataset * @param a//from w ww . jav a 2 s .c o m * @param o output can be null - in which case, a new dataset is created * @return dataset */ public static Dataset tan(final Object a, final Dataset o) { final Dataset da = a instanceof Dataset ? (Dataset) a : DatasetFactory.createFromObject(a); final SingleInputBroadcastIterator it = new SingleInputBroadcastIterator(da, o, true); final Dataset result = it.getOutput(); final int is = result.getElementsPerItem(); final int as = da.getElementsPerItem(); final int dt = result.getDType(); switch (dt) { case Dataset.INT8: final byte[] oi8data = ((ByteDataset) result).getData(); if (it.isOutputDouble()) { while (it.hasNext()) { final double ix = it.aDouble; byte ox; ox = (byte) toLong(Math.tan(ix)); oi8data[it.oIndex] = ox; } } else { while (it.hasNext()) { final long ix = it.aLong; byte ox; ox = (byte) toLong(Math.tan(ix)); oi8data[it.oIndex] = ox; } } break; case Dataset.INT16: final short[] oi16data = ((ShortDataset) result).getData(); if (it.isOutputDouble()) { while (it.hasNext()) { final double ix = it.aDouble; short ox; ox = (short) toLong(Math.tan(ix)); oi16data[it.oIndex] = ox; } } else { while (it.hasNext()) { final long ix = it.aLong; short ox; ox = (short) toLong(Math.tan(ix)); oi16data[it.oIndex] = ox; } } break; case Dataset.INT64: final long[] oi64data = ((LongDataset) result).getData(); if (it.isOutputDouble()) { while (it.hasNext()) { final double ix = it.aDouble; long ox; ox = toLong(Math.tan(ix)); oi64data[it.oIndex] = ox; } } else { while (it.hasNext()) { final long ix = it.aLong; long ox; ox = toLong(Math.tan(ix)); oi64data[it.oIndex] = ox; } } break; case Dataset.INT32: final int[] oi32data = ((IntegerDataset) result).getData(); if (it.isOutputDouble()) { while (it.hasNext()) { final double ix = it.aDouble; int ox; ox = (int) toLong(Math.tan(ix)); oi32data[it.oIndex] = ox; } } else { while (it.hasNext()) { final long ix = it.aLong; int ox; ox = (int) toLong(Math.tan(ix)); oi32data[it.oIndex] = ox; } } break; case Dataset.ARRAYINT8: final byte[] oai8data = ((CompoundByteDataset) result).getData(); if (is == 1) { if (it.isOutputDouble()) { while (it.hasNext()) { final double ix = it.aDouble; byte ox; ox = (byte) toLong(Math.tan(ix)); oai8data[it.oIndex] = ox; } } else { while (it.hasNext()) { final long ix = it.aLong; byte ox; ox = (byte) toLong(Math.tan(ix)); oai8data[it.oIndex] = ox; } } } else if (as == 1) { if (it.isOutputDouble()) { while (it.hasNext()) { final double ix = it.aDouble; byte ox; ox = (byte) toLong(Math.tan(ix)); for (int j = 0; j < is; j++) { oai8data[it.oIndex + j] = ox; } } } else { while (it.hasNext()) { final long ix = it.aLong; byte ox; ox = (byte) toLong(Math.tan(ix)); for (int j = 0; j < is; j++) { oai8data[it.oIndex + j] = ox; } } } } else { if (it.isOutputDouble()) { while (it.hasNext()) { for (int j = 0; j < is; j++) { final double ix = da.getElementDoubleAbs(it.aIndex + j); byte ox; ox = (byte) toLong(Math.tan(ix)); oai8data[it.oIndex + j] = ox; } } } else { while (it.hasNext()) { for (int j = 0; j < is; j++) { final long ix = da.getElementLongAbs(it.aIndex + j); byte ox; ox = (byte) toLong(Math.tan(ix)); oai8data[it.oIndex + j] = ox; } } } } break; case Dataset.ARRAYINT16: final short[] oai16data = ((CompoundShortDataset) result).getData(); if (is == 1) { if (it.isOutputDouble()) { while (it.hasNext()) { final double ix = it.aDouble; short ox; ox = (short) toLong(Math.tan(ix)); oai16data[it.oIndex] = ox; } } else { while (it.hasNext()) { final long ix = it.aLong; short ox; ox = (short) toLong(Math.tan(ix)); oai16data[it.oIndex] = ox; } } } else if (as == 1) { if (it.isOutputDouble()) { while (it.hasNext()) { final double ix = it.aDouble; short ox; ox = (short) toLong(Math.tan(ix)); for (int j = 0; j < is; j++) { oai16data[it.oIndex + j] = ox; } } } else { while (it.hasNext()) { final long ix = it.aLong; short ox; ox = (short) toLong(Math.tan(ix)); for (int j = 0; j < is; j++) { oai16data[it.oIndex + j] = ox; } } } } else { if (it.isOutputDouble()) { while (it.hasNext()) { for (int j = 0; j < is; j++) { final double ix = da.getElementDoubleAbs(it.aIndex + j); short ox; ox = (short) toLong(Math.tan(ix)); oai16data[it.oIndex + j] = ox; } } } else { while (it.hasNext()) { for (int j = 0; j < is; j++) { final long ix = da.getElementLongAbs(it.aIndex + j); short ox; ox = (short) toLong(Math.tan(ix)); oai16data[it.oIndex + j] = ox; } } } } break; case Dataset.ARRAYINT64: final long[] oai64data = ((CompoundLongDataset) result).getData(); if (is == 1) { if (it.isOutputDouble()) { while (it.hasNext()) { final double ix = it.aDouble; long ox; ox = toLong(Math.tan(ix)); oai64data[it.oIndex] = ox; } } else { while (it.hasNext()) { final long ix = it.aLong; long ox; ox = toLong(Math.tan(ix)); oai64data[it.oIndex] = ox; } } } else if (as == 1) { if (it.isOutputDouble()) { while (it.hasNext()) { final double ix = it.aDouble; long ox; ox = toLong(Math.tan(ix)); for (int j = 0; j < is; j++) { oai64data[it.oIndex + j] = ox; } } } else { while (it.hasNext()) { final long ix = it.aLong; long ox; ox = toLong(Math.tan(ix)); for (int j = 0; j < is; j++) { oai64data[it.oIndex + j] = ox; } } } } else { if (it.isOutputDouble()) { while (it.hasNext()) { for (int j = 0; j < is; j++) { final double ix = da.getElementDoubleAbs(it.aIndex + j); long ox; ox = toLong(Math.tan(ix)); oai64data[it.oIndex + j] = ox; } } } else { while (it.hasNext()) { for (int j = 0; j < is; j++) { final long ix = da.getElementLongAbs(it.aIndex + j); long ox; ox = toLong(Math.tan(ix)); oai64data[it.oIndex + j] = ox; } } } } break; case Dataset.ARRAYINT32: final int[] oai32data = ((CompoundIntegerDataset) result).getData(); if (is == 1) { if (it.isOutputDouble()) { while (it.hasNext()) { final double ix = it.aDouble; int ox; ox = (int) toLong(Math.tan(ix)); oai32data[it.oIndex] = ox; } } else { while (it.hasNext()) { final long ix = it.aLong; int ox; ox = (int) toLong(Math.tan(ix)); oai32data[it.oIndex] = ox; } } } else if (as == 1) { if (it.isOutputDouble()) { while (it.hasNext()) { final double ix = it.aDouble; int ox; ox = (int) toLong(Math.tan(ix)); for (int j = 0; j < is; j++) { oai32data[it.oIndex + j] = ox; } } } else { while (it.hasNext()) { final long ix = it.aLong; int ox; ox = (int) toLong(Math.tan(ix)); for (int j = 0; j < is; j++) { oai32data[it.oIndex + j] = ox; } } } } else { if (it.isOutputDouble()) { while (it.hasNext()) { for (int j = 0; j < is; j++) { final double ix = da.getElementDoubleAbs(it.aIndex + j); int ox; ox = (int) toLong(Math.tan(ix)); oai32data[it.oIndex + j] = ox; } } } else { while (it.hasNext()) { for (int j = 0; j < is; j++) { final long ix = da.getElementLongAbs(it.aIndex + j); int ox; ox = (int) toLong(Math.tan(ix)); oai32data[it.oIndex + j] = ox; } } } } break; case Dataset.FLOAT32: final float[] of32data = ((FloatDataset) result).getData(); if (it.isOutputDouble()) { while (it.hasNext()) { final double ix = it.aDouble; float ox; ox = (float) (Math.tan(ix)); of32data[it.oIndex] = ox; } } else { while (it.hasNext()) { final long ix = it.aLong; float ox; ox = (float) (Math.tan(ix)); of32data[it.oIndex] = ox; } } break; case Dataset.FLOAT64: final double[] of64data = ((DoubleDataset) result).getData(); if (it.isOutputDouble()) { while (it.hasNext()) { final double ix = it.aDouble; double ox; ox = (Math.tan(ix)); of64data[it.oIndex] = ox; } } else { while (it.hasNext()) { final long ix = it.aLong; double ox; ox = (Math.tan(ix)); of64data[it.oIndex] = ox; } } break; case Dataset.ARRAYFLOAT32: final float[] oaf32data = ((CompoundFloatDataset) result).getData(); if (is == 1) { if (it.isOutputDouble()) { while (it.hasNext()) { final double ix = it.aDouble; float ox; ox = (float) (Math.tan(ix)); oaf32data[it.oIndex] = ox; } } else { while (it.hasNext()) { final long ix = it.aLong; float ox; ox = (float) (Math.tan(ix)); oaf32data[it.oIndex] = ox; } } } else if (as == 1) { if (it.isOutputDouble()) { while (it.hasNext()) { final double ix = it.aDouble; float ox; ox = (float) (Math.tan(ix)); for (int j = 0; j < is; j++) { oaf32data[it.oIndex + j] = ox; } } } else { while (it.hasNext()) { final long ix = it.aLong; float ox; ox = (float) (Math.tan(ix)); for (int j = 0; j < is; j++) { oaf32data[it.oIndex + j] = ox; } } } } else { if (it.isOutputDouble()) { while (it.hasNext()) { for (int j = 0; j < is; j++) { final double ix = da.getElementDoubleAbs(it.aIndex + j); float ox; ox = (float) (Math.tan(ix)); oaf32data[it.oIndex + j] = ox; } } } else { while (it.hasNext()) { for (int j = 0; j < is; j++) { final long ix = da.getElementLongAbs(it.aIndex + j); float ox; ox = (float) (Math.tan(ix)); oaf32data[it.oIndex + j] = ox; } } } } break; case Dataset.ARRAYFLOAT64: final double[] oaf64data = ((CompoundDoubleDataset) result).getData(); if (is == 1) { if (it.isOutputDouble()) { while (it.hasNext()) { final double ix = it.aDouble; double ox; ox = (Math.tan(ix)); oaf64data[it.oIndex] = ox; } } else { while (it.hasNext()) { final long ix = it.aLong; double ox; ox = (Math.tan(ix)); oaf64data[it.oIndex] = ox; } } } else if (as == 1) { if (it.isOutputDouble()) { while (it.hasNext()) { final double ix = it.aDouble; double ox; ox = (Math.tan(ix)); for (int j = 0; j < is; j++) { oaf64data[it.oIndex + j] = ox; } } } else { while (it.hasNext()) { final long ix = it.aLong; double ox; ox = (Math.tan(ix)); for (int j = 0; j < is; j++) { oaf64data[it.oIndex + j] = ox; } } } } else { if (it.isOutputDouble()) { while (it.hasNext()) { for (int j = 0; j < is; j++) { final double ix = da.getElementDoubleAbs(it.aIndex + j); double ox; ox = (Math.tan(ix)); oaf64data[it.oIndex + j] = ox; } } } else { while (it.hasNext()) { for (int j = 0; j < is; j++) { final long ix = da.getElementLongAbs(it.aIndex + j); double ox; ox = (Math.tan(ix)); oaf64data[it.oIndex + j] = ox; } } } } break; case Dataset.COMPLEX64: final float[] oc64data = ((ComplexFloatDataset) result).getData(); if (as == 1) { final double iy = 0; while (it.hasNext()) { final double ix = it.aDouble; float x; float y; float tf; float ox; float oy; x = (float) (2. * ix); y = (float) (2. * iy); tf = (float) (1. / (Math.cos(x) + Math.cosh(y))); ox = (float) (tf * Math.sin(x)); oy = (float) (tf * Math.sinh(y)); oc64data[it.oIndex] = ox; oc64data[it.oIndex + 1] = oy; } } else { while (it.hasNext()) { final double ix = it.aDouble; final double iy = da.getElementDoubleAbs(it.aIndex + 1); float x; float y; float tf; float ox; float oy; x = (float) (2. * ix); y = (float) (2. * iy); tf = (float) (1. / (Math.cos(x) + Math.cosh(y))); ox = (float) (tf * Math.sin(x)); oy = (float) (tf * Math.sinh(y)); oc64data[it.oIndex] = ox; oc64data[it.oIndex + 1] = oy; } } break; case Dataset.COMPLEX128: final double[] oc128data = ((ComplexDoubleDataset) result).getData(); if (as == 1) { final double iy = 0; while (it.hasNext()) { final double ix = it.aDouble; double x; double y; double tf; double ox; double oy; x = (2. * ix); y = (2. * iy); tf = (1. / (Math.cos(x) + Math.cosh(y))); ox = (tf * Math.sin(x)); oy = (tf * Math.sinh(y)); oc128data[it.oIndex] = ox; oc128data[it.oIndex + 1] = oy; } } else { while (it.hasNext()) { final double ix = it.aDouble; final double iy = da.getElementDoubleAbs(it.aIndex + 1); double x; double y; double tf; double ox; double oy; x = (2. * ix); y = (2. * iy); tf = (1. / (Math.cos(x) + Math.cosh(y))); ox = (tf * Math.sin(x)); oy = (tf * Math.sinh(y)); oc128data[it.oIndex] = ox; oc128data[it.oIndex + 1] = oy; } } break; default: throw new IllegalArgumentException( "tan supports integer, compound integer, real, compound real, complex datasets only"); } addFunctionName(result, "tan"); return result; }
From source file:org.eclipse.january.dataset.Maths.java
/** * tan - evaluate the tangent function on each element of the dataset * @param a//from w w w . j av a 2 s .c o m * @param o output can be null - in which case, a new dataset is created * @return dataset */ public static Dataset tan(final Object a, final Dataset o) { final Dataset da = a instanceof Dataset ? (Dataset) a : DatasetFactory.createFromObject(a); final SingleInputBroadcastIterator it = new SingleInputBroadcastIterator(da, o, true); final Dataset result = it.getOutput(); final int is = result.getElementsPerItem(); final int dt = result.getDType(); switch (dt) { case Dataset.INT8: final byte[] oi8data = ((ByteDataset) result).data; if (it.isOutputDouble()) { while (it.hasNext()) { final double ix = it.aDouble; byte ox; ox = (byte) toLong(Math.tan(ix)); oi8data[it.oIndex] = ox; } } else { while (it.hasNext()) { final long ix = it.aLong; byte ox; ox = (byte) toLong(Math.tan(ix)); oi8data[it.oIndex] = ox; } } break; case Dataset.INT16: final short[] oi16data = ((ShortDataset) result).data; if (it.isOutputDouble()) { while (it.hasNext()) { final double ix = it.aDouble; short ox; ox = (short) toLong(Math.tan(ix)); oi16data[it.oIndex] = ox; } } else { while (it.hasNext()) { final long ix = it.aLong; short ox; ox = (short) toLong(Math.tan(ix)); oi16data[it.oIndex] = ox; } } break; case Dataset.INT64: final long[] oi64data = ((LongDataset) result).data; if (it.isOutputDouble()) { while (it.hasNext()) { final double ix = it.aDouble; long ox; ox = toLong(Math.tan(ix)); oi64data[it.oIndex] = ox; } } else { while (it.hasNext()) { final long ix = it.aLong; long ox; ox = toLong(Math.tan(ix)); oi64data[it.oIndex] = ox; } } break; case Dataset.INT32: final int[] oi32data = ((IntegerDataset) result).data; if (it.isOutputDouble()) { while (it.hasNext()) { final double ix = it.aDouble; int ox; ox = (int) toLong(Math.tan(ix)); oi32data[it.oIndex] = ox; } } else { while (it.hasNext()) { final long ix = it.aLong; int ox; ox = (int) toLong(Math.tan(ix)); oi32data[it.oIndex] = ox; } } break; case Dataset.ARRAYINT8: final byte[] oai8data = ((CompoundByteDataset) result).data; if (is == 1) { if (it.isOutputDouble()) { while (it.hasNext()) { final double ix = it.aDouble; byte ox; ox = (byte) toLong(Math.tan(ix)); oai8data[it.oIndex] = ox; } } else { while (it.hasNext()) { final long ix = it.aLong; byte ox; ox = (byte) toLong(Math.tan(ix)); oai8data[it.oIndex] = ox; } } } else if (da.getElementsPerItem() == 1) { if (it.isOutputDouble()) { while (it.hasNext()) { final double ix = it.aDouble; byte ox; ox = (byte) toLong(Math.tan(ix)); for (int j = 0; j < is; j++) { oai8data[it.oIndex + j] = ox; } } } else { while (it.hasNext()) { final long ix = it.aLong; byte ox; ox = (byte) toLong(Math.tan(ix)); for (int j = 0; j < is; j++) { oai8data[it.oIndex + j] = ox; } } } } else { if (it.isOutputDouble()) { while (it.hasNext()) { for (int j = 0; j < is; j++) { final double ix = da.getElementDoubleAbs(it.aIndex + j); byte ox; ox = (byte) toLong(Math.tan(ix)); oai8data[it.oIndex + j] = ox; } } } else { while (it.hasNext()) { for (int j = 0; j < is; j++) { final long ix = da.getElementLongAbs(it.aIndex + j); byte ox; ox = (byte) toLong(Math.tan(ix)); oai8data[it.oIndex + j] = ox; } } } } break; case Dataset.ARRAYINT16: final short[] oai16data = ((CompoundShortDataset) result).data; if (is == 1) { if (it.isOutputDouble()) { while (it.hasNext()) { final double ix = it.aDouble; short ox; ox = (short) toLong(Math.tan(ix)); oai16data[it.oIndex] = ox; } } else { while (it.hasNext()) { final long ix = it.aLong; short ox; ox = (short) toLong(Math.tan(ix)); oai16data[it.oIndex] = ox; } } } else if (da.getElementsPerItem() == 1) { if (it.isOutputDouble()) { while (it.hasNext()) { final double ix = it.aDouble; short ox; ox = (short) toLong(Math.tan(ix)); for (int j = 0; j < is; j++) { oai16data[it.oIndex + j] = ox; } } } else { while (it.hasNext()) { final long ix = it.aLong; short ox; ox = (short) toLong(Math.tan(ix)); for (int j = 0; j < is; j++) { oai16data[it.oIndex + j] = ox; } } } } else { if (it.isOutputDouble()) { while (it.hasNext()) { for (int j = 0; j < is; j++) { final double ix = da.getElementDoubleAbs(it.aIndex + j); short ox; ox = (short) toLong(Math.tan(ix)); oai16data[it.oIndex + j] = ox; } } } else { while (it.hasNext()) { for (int j = 0; j < is; j++) { final long ix = da.getElementLongAbs(it.aIndex + j); short ox; ox = (short) toLong(Math.tan(ix)); oai16data[it.oIndex + j] = ox; } } } } break; case Dataset.ARRAYINT64: final long[] oai64data = ((CompoundLongDataset) result).data; if (is == 1) { if (it.isOutputDouble()) { while (it.hasNext()) { final double ix = it.aDouble; long ox; ox = toLong(Math.tan(ix)); oai64data[it.oIndex] = ox; } } else { while (it.hasNext()) { final long ix = it.aLong; long ox; ox = toLong(Math.tan(ix)); oai64data[it.oIndex] = ox; } } } else if (da.getElementsPerItem() == 1) { if (it.isOutputDouble()) { while (it.hasNext()) { final double ix = it.aDouble; long ox; ox = toLong(Math.tan(ix)); for (int j = 0; j < is; j++) { oai64data[it.oIndex + j] = ox; } } } else { while (it.hasNext()) { final long ix = it.aLong; long ox; ox = toLong(Math.tan(ix)); for (int j = 0; j < is; j++) { oai64data[it.oIndex + j] = ox; } } } } else { if (it.isOutputDouble()) { while (it.hasNext()) { for (int j = 0; j < is; j++) { final double ix = da.getElementDoubleAbs(it.aIndex + j); long ox; ox = toLong(Math.tan(ix)); oai64data[it.oIndex + j] = ox; } } } else { while (it.hasNext()) { for (int j = 0; j < is; j++) { final long ix = da.getElementLongAbs(it.aIndex + j); long ox; ox = toLong(Math.tan(ix)); oai64data[it.oIndex + j] = ox; } } } } break; case Dataset.ARRAYINT32: final int[] oai32data = ((CompoundIntegerDataset) result).data; if (is == 1) { if (it.isOutputDouble()) { while (it.hasNext()) { final double ix = it.aDouble; int ox; ox = (int) toLong(Math.tan(ix)); oai32data[it.oIndex] = ox; } } else { while (it.hasNext()) { final long ix = it.aLong; int ox; ox = (int) toLong(Math.tan(ix)); oai32data[it.oIndex] = ox; } } } else if (da.getElementsPerItem() == 1) { if (it.isOutputDouble()) { while (it.hasNext()) { final double ix = it.aDouble; int ox; ox = (int) toLong(Math.tan(ix)); for (int j = 0; j < is; j++) { oai32data[it.oIndex + j] = ox; } } } else { while (it.hasNext()) { final long ix = it.aLong; int ox; ox = (int) toLong(Math.tan(ix)); for (int j = 0; j < is; j++) { oai32data[it.oIndex + j] = ox; } } } } else { if (it.isOutputDouble()) { while (it.hasNext()) { for (int j = 0; j < is; j++) { final double ix = da.getElementDoubleAbs(it.aIndex + j); int ox; ox = (int) toLong(Math.tan(ix)); oai32data[it.oIndex + j] = ox; } } } else { while (it.hasNext()) { for (int j = 0; j < is; j++) { final long ix = da.getElementLongAbs(it.aIndex + j); int ox; ox = (int) toLong(Math.tan(ix)); oai32data[it.oIndex + j] = ox; } } } } break; case Dataset.FLOAT32: final float[] of32data = ((FloatDataset) result).data; if (it.isOutputDouble()) { while (it.hasNext()) { final double ix = it.aDouble; float ox; ox = (float) (Math.tan(ix)); of32data[it.oIndex] = ox; } } else { while (it.hasNext()) { final long ix = it.aLong; float ox; ox = (float) (Math.tan(ix)); of32data[it.oIndex] = ox; } } break; case Dataset.FLOAT64: final double[] of64data = ((DoubleDataset) result).data; if (it.isOutputDouble()) { while (it.hasNext()) { final double ix = it.aDouble; double ox; ox = (Math.tan(ix)); of64data[it.oIndex] = ox; } } else { while (it.hasNext()) { final long ix = it.aLong; double ox; ox = (Math.tan(ix)); of64data[it.oIndex] = ox; } } break; case Dataset.ARRAYFLOAT32: final float[] oaf32data = ((CompoundFloatDataset) result).data; if (is == 1) { if (it.isOutputDouble()) { while (it.hasNext()) { final double ix = it.aDouble; float ox; ox = (float) (Math.tan(ix)); oaf32data[it.oIndex] = ox; } } else { while (it.hasNext()) { final long ix = it.aLong; float ox; ox = (float) (Math.tan(ix)); oaf32data[it.oIndex] = ox; } } } else if (da.getElementsPerItem() == 1) { if (it.isOutputDouble()) { while (it.hasNext()) { final double ix = it.aDouble; float ox; ox = (float) (Math.tan(ix)); for (int j = 0; j < is; j++) { oaf32data[it.oIndex + j] = ox; } } } else { while (it.hasNext()) { final long ix = it.aLong; float ox; ox = (float) (Math.tan(ix)); for (int j = 0; j < is; j++) { oaf32data[it.oIndex + j] = ox; } } } } else { if (it.isOutputDouble()) { while (it.hasNext()) { for (int j = 0; j < is; j++) { final double ix = da.getElementDoubleAbs(it.aIndex + j); float ox; ox = (float) (Math.tan(ix)); oaf32data[it.oIndex + j] = ox; } } } else { while (it.hasNext()) { for (int j = 0; j < is; j++) { final long ix = da.getElementLongAbs(it.aIndex + j); float ox; ox = (float) (Math.tan(ix)); oaf32data[it.oIndex + j] = ox; } } } } break; case Dataset.ARRAYFLOAT64: final double[] oaf64data = ((CompoundDoubleDataset) result).data; if (is == 1) { if (it.isOutputDouble()) { while (it.hasNext()) { final double ix = it.aDouble; double ox; ox = (Math.tan(ix)); oaf64data[it.oIndex] = ox; } } else { while (it.hasNext()) { final long ix = it.aLong; double ox; ox = (Math.tan(ix)); oaf64data[it.oIndex] = ox; } } } else if (da.getElementsPerItem() == 1) { if (it.isOutputDouble()) { while (it.hasNext()) { final double ix = it.aDouble; double ox; ox = (Math.tan(ix)); for (int j = 0; j < is; j++) { oaf64data[it.oIndex + j] = ox; } } } else { while (it.hasNext()) { final long ix = it.aLong; double ox; ox = (Math.tan(ix)); for (int j = 0; j < is; j++) { oaf64data[it.oIndex + j] = ox; } } } } else { if (it.isOutputDouble()) { while (it.hasNext()) { for (int j = 0; j < is; j++) { final double ix = da.getElementDoubleAbs(it.aIndex + j); double ox; ox = (Math.tan(ix)); oaf64data[it.oIndex + j] = ox; } } } else { while (it.hasNext()) { for (int j = 0; j < is; j++) { final long ix = da.getElementLongAbs(it.aIndex + j); double ox; ox = (Math.tan(ix)); oaf64data[it.oIndex + j] = ox; } } } } break; case Dataset.COMPLEX64: final float[] oc64data = ((ComplexFloatDataset) result).data; if (da.getElementsPerItem() == 1) { final double iy = 0; while (it.hasNext()) { final double ix = it.aDouble; float x; float y; float tf; float ox; float oy; x = (float) (2. * ix); y = (float) (2. * iy); tf = (float) (1. / (Math.cos(x) + Math.cosh(y))); ox = (float) (tf * Math.sin(x)); oy = (float) (tf * Math.sinh(y)); oc64data[it.oIndex] = ox; oc64data[it.oIndex + 1] = oy; } } else { while (it.hasNext()) { final double ix = it.aDouble; final double iy = da.getElementDoubleAbs(it.aIndex + 1); float x; float y; float tf; float ox; float oy; x = (float) (2. * ix); y = (float) (2. * iy); tf = (float) (1. / (Math.cos(x) + Math.cosh(y))); ox = (float) (tf * Math.sin(x)); oy = (float) (tf * Math.sinh(y)); oc64data[it.oIndex] = ox; oc64data[it.oIndex + 1] = oy; } } break; case Dataset.COMPLEX128: final double[] oc128data = ((ComplexDoubleDataset) result).data; if (da.getElementsPerItem() == 1) { final double iy = 0; while (it.hasNext()) { final double ix = it.aDouble; double x; double y; double tf; double ox; double oy; x = (2. * ix); y = (2. * iy); tf = (1. / (Math.cos(x) + Math.cosh(y))); ox = (tf * Math.sin(x)); oy = (tf * Math.sinh(y)); oc128data[it.oIndex] = ox; oc128data[it.oIndex + 1] = oy; } } else { while (it.hasNext()) { final double ix = it.aDouble; final double iy = da.getElementDoubleAbs(it.aIndex + 1); double x; double y; double tf; double ox; double oy; x = (2. * ix); y = (2. * iy); tf = (1. / (Math.cos(x) + Math.cosh(y))); ox = (tf * Math.sin(x)); oy = (tf * Math.sinh(y)); oc128data[it.oIndex] = ox; oc128data[it.oIndex + 1] = oy; } } break; default: throw new IllegalArgumentException( "tan supports integer, compound integer, real, compound real, complex datasets only"); } addFunctionName(result, "tan"); return result; }
From source file:org.eclipse.dataset.Maths.java
/** * tan - evaluate the tangent function on each element of the dataset * @param a//from w ww . j a va 2 s . c o m * @param o output can be null - in which case, a new dataset is created * @return dataset */ public static Dataset tan(final Object a, final Dataset o) { final Dataset da = a instanceof Dataset ? (Dataset) a : DatasetFactory.createFromObject(a); final SingleInputBroadcastIterator it = new SingleInputBroadcastIterator(da, o, true); final Dataset result = it.getOutput(); final int is = result.getElementsPerItem(); final int dt = result.getDtype(); switch (dt) { case Dataset.INT8: final byte[] oi8data = ((ByteDataset) result).data; if (it.isOutputDouble()) { while (it.hasNext()) { final double ix = it.aDouble; byte ox; ox = (byte) toLong(Math.tan(ix)); oi8data[it.oIndex] = ox; } } else { while (it.hasNext()) { final long ix = it.aLong; byte ox; ox = (byte) toLong(Math.tan(ix)); oi8data[it.oIndex] = ox; } } break; case Dataset.INT16: final short[] oi16data = ((ShortDataset) result).data; if (it.isOutputDouble()) { while (it.hasNext()) { final double ix = it.aDouble; short ox; ox = (short) toLong(Math.tan(ix)); oi16data[it.oIndex] = ox; } } else { while (it.hasNext()) { final long ix = it.aLong; short ox; ox = (short) toLong(Math.tan(ix)); oi16data[it.oIndex] = ox; } } break; case Dataset.INT64: final long[] oi64data = ((LongDataset) result).data; if (it.isOutputDouble()) { while (it.hasNext()) { final double ix = it.aDouble; long ox; ox = toLong(Math.tan(ix)); oi64data[it.oIndex] = ox; } } else { while (it.hasNext()) { final long ix = it.aLong; long ox; ox = toLong(Math.tan(ix)); oi64data[it.oIndex] = ox; } } break; case Dataset.INT32: final int[] oi32data = ((IntegerDataset) result).data; if (it.isOutputDouble()) { while (it.hasNext()) { final double ix = it.aDouble; int ox; ox = (int) toLong(Math.tan(ix)); oi32data[it.oIndex] = ox; } } else { while (it.hasNext()) { final long ix = it.aLong; int ox; ox = (int) toLong(Math.tan(ix)); oi32data[it.oIndex] = ox; } } break; case Dataset.ARRAYINT8: final byte[] oai8data = ((CompoundByteDataset) result).data; if (is == 1) { if (it.isOutputDouble()) { while (it.hasNext()) { final double ix = it.aDouble; byte ox; ox = (byte) toLong(Math.tan(ix)); oai8data[it.oIndex] = ox; } } else { while (it.hasNext()) { final long ix = it.aLong; byte ox; ox = (byte) toLong(Math.tan(ix)); oai8data[it.oIndex] = ox; } } } else if (da.getElementsPerItem() == 1) { if (it.isOutputDouble()) { while (it.hasNext()) { final double ix = it.aDouble; byte ox; ox = (byte) toLong(Math.tan(ix)); for (int j = 0; j < is; j++) { oai8data[it.oIndex + j] = ox; } } } else { while (it.hasNext()) { final long ix = it.aLong; byte ox; ox = (byte) toLong(Math.tan(ix)); for (int j = 0; j < is; j++) { oai8data[it.oIndex + j] = ox; } } } } else { if (it.isOutputDouble()) { while (it.hasNext()) { for (int j = 0; j < is; j++) { final double ix = da.getElementDoubleAbs(it.aIndex + j); byte ox; ox = (byte) toLong(Math.tan(ix)); oai8data[it.oIndex + j] = ox; } } } else { while (it.hasNext()) { for (int j = 0; j < is; j++) { final long ix = da.getElementLongAbs(it.aIndex + j); byte ox; ox = (byte) toLong(Math.tan(ix)); oai8data[it.oIndex + j] = ox; } } } } break; case Dataset.ARRAYINT16: final short[] oai16data = ((CompoundShortDataset) result).data; if (is == 1) { if (it.isOutputDouble()) { while (it.hasNext()) { final double ix = it.aDouble; short ox; ox = (short) toLong(Math.tan(ix)); oai16data[it.oIndex] = ox; } } else { while (it.hasNext()) { final long ix = it.aLong; short ox; ox = (short) toLong(Math.tan(ix)); oai16data[it.oIndex] = ox; } } } else if (da.getElementsPerItem() == 1) { if (it.isOutputDouble()) { while (it.hasNext()) { final double ix = it.aDouble; short ox; ox = (short) toLong(Math.tan(ix)); for (int j = 0; j < is; j++) { oai16data[it.oIndex + j] = ox; } } } else { while (it.hasNext()) { final long ix = it.aLong; short ox; ox = (short) toLong(Math.tan(ix)); for (int j = 0; j < is; j++) { oai16data[it.oIndex + j] = ox; } } } } else { if (it.isOutputDouble()) { while (it.hasNext()) { for (int j = 0; j < is; j++) { final double ix = da.getElementDoubleAbs(it.aIndex + j); short ox; ox = (short) toLong(Math.tan(ix)); oai16data[it.oIndex + j] = ox; } } } else { while (it.hasNext()) { for (int j = 0; j < is; j++) { final long ix = da.getElementLongAbs(it.aIndex + j); short ox; ox = (short) toLong(Math.tan(ix)); oai16data[it.oIndex + j] = ox; } } } } break; case Dataset.ARRAYINT64: final long[] oai64data = ((CompoundLongDataset) result).data; if (is == 1) { if (it.isOutputDouble()) { while (it.hasNext()) { final double ix = it.aDouble; long ox; ox = toLong(Math.tan(ix)); oai64data[it.oIndex] = ox; } } else { while (it.hasNext()) { final long ix = it.aLong; long ox; ox = toLong(Math.tan(ix)); oai64data[it.oIndex] = ox; } } } else if (da.getElementsPerItem() == 1) { if (it.isOutputDouble()) { while (it.hasNext()) { final double ix = it.aDouble; long ox; ox = toLong(Math.tan(ix)); for (int j = 0; j < is; j++) { oai64data[it.oIndex + j] = ox; } } } else { while (it.hasNext()) { final long ix = it.aLong; long ox; ox = toLong(Math.tan(ix)); for (int j = 0; j < is; j++) { oai64data[it.oIndex + j] = ox; } } } } else { if (it.isOutputDouble()) { while (it.hasNext()) { for (int j = 0; j < is; j++) { final double ix = da.getElementDoubleAbs(it.aIndex + j); long ox; ox = toLong(Math.tan(ix)); oai64data[it.oIndex + j] = ox; } } } else { while (it.hasNext()) { for (int j = 0; j < is; j++) { final long ix = da.getElementLongAbs(it.aIndex + j); long ox; ox = toLong(Math.tan(ix)); oai64data[it.oIndex + j] = ox; } } } } break; case Dataset.ARRAYINT32: final int[] oai32data = ((CompoundIntegerDataset) result).data; if (is == 1) { if (it.isOutputDouble()) { while (it.hasNext()) { final double ix = it.aDouble; int ox; ox = (int) toLong(Math.tan(ix)); oai32data[it.oIndex] = ox; } } else { while (it.hasNext()) { final long ix = it.aLong; int ox; ox = (int) toLong(Math.tan(ix)); oai32data[it.oIndex] = ox; } } } else if (da.getElementsPerItem() == 1) { if (it.isOutputDouble()) { while (it.hasNext()) { final double ix = it.aDouble; int ox; ox = (int) toLong(Math.tan(ix)); for (int j = 0; j < is; j++) { oai32data[it.oIndex + j] = ox; } } } else { while (it.hasNext()) { final long ix = it.aLong; int ox; ox = (int) toLong(Math.tan(ix)); for (int j = 0; j < is; j++) { oai32data[it.oIndex + j] = ox; } } } } else { if (it.isOutputDouble()) { while (it.hasNext()) { for (int j = 0; j < is; j++) { final double ix = da.getElementDoubleAbs(it.aIndex + j); int ox; ox = (int) toLong(Math.tan(ix)); oai32data[it.oIndex + j] = ox; } } } else { while (it.hasNext()) { for (int j = 0; j < is; j++) { final long ix = da.getElementLongAbs(it.aIndex + j); int ox; ox = (int) toLong(Math.tan(ix)); oai32data[it.oIndex + j] = ox; } } } } break; case Dataset.FLOAT32: final float[] of32data = ((FloatDataset) result).data; if (it.isOutputDouble()) { while (it.hasNext()) { final double ix = it.aDouble; float ox; ox = (float) (Math.tan(ix)); of32data[it.oIndex] = ox; } } else { while (it.hasNext()) { final long ix = it.aLong; float ox; ox = (float) (Math.tan(ix)); of32data[it.oIndex] = ox; } } break; case Dataset.FLOAT64: final double[] of64data = ((DoubleDataset) result).data; if (it.isOutputDouble()) { while (it.hasNext()) { final double ix = it.aDouble; double ox; ox = (Math.tan(ix)); of64data[it.oIndex] = ox; } } else { while (it.hasNext()) { final long ix = it.aLong; double ox; ox = (Math.tan(ix)); of64data[it.oIndex] = ox; } } break; case Dataset.ARRAYFLOAT32: final float[] oaf32data = ((CompoundFloatDataset) result).data; if (is == 1) { if (it.isOutputDouble()) { while (it.hasNext()) { final double ix = it.aDouble; float ox; ox = (float) (Math.tan(ix)); oaf32data[it.oIndex] = ox; } } else { while (it.hasNext()) { final long ix = it.aLong; float ox; ox = (float) (Math.tan(ix)); oaf32data[it.oIndex] = ox; } } } else if (da.getElementsPerItem() == 1) { if (it.isOutputDouble()) { while (it.hasNext()) { final double ix = it.aDouble; float ox; ox = (float) (Math.tan(ix)); for (int j = 0; j < is; j++) { oaf32data[it.oIndex + j] = ox; } } } else { while (it.hasNext()) { final long ix = it.aLong; float ox; ox = (float) (Math.tan(ix)); for (int j = 0; j < is; j++) { oaf32data[it.oIndex + j] = ox; } } } } else { if (it.isOutputDouble()) { while (it.hasNext()) { for (int j = 0; j < is; j++) { final double ix = da.getElementDoubleAbs(it.aIndex + j); float ox; ox = (float) (Math.tan(ix)); oaf32data[it.oIndex + j] = ox; } } } else { while (it.hasNext()) { for (int j = 0; j < is; j++) { final long ix = da.getElementLongAbs(it.aIndex + j); float ox; ox = (float) (Math.tan(ix)); oaf32data[it.oIndex + j] = ox; } } } } break; case Dataset.ARRAYFLOAT64: final double[] oaf64data = ((CompoundDoubleDataset) result).data; if (is == 1) { if (it.isOutputDouble()) { while (it.hasNext()) { final double ix = it.aDouble; double ox; ox = (Math.tan(ix)); oaf64data[it.oIndex] = ox; } } else { while (it.hasNext()) { final long ix = it.aLong; double ox; ox = (Math.tan(ix)); oaf64data[it.oIndex] = ox; } } } else if (da.getElementsPerItem() == 1) { if (it.isOutputDouble()) { while (it.hasNext()) { final double ix = it.aDouble; double ox; ox = (Math.tan(ix)); for (int j = 0; j < is; j++) { oaf64data[it.oIndex + j] = ox; } } } else { while (it.hasNext()) { final long ix = it.aLong; double ox; ox = (Math.tan(ix)); for (int j = 0; j < is; j++) { oaf64data[it.oIndex + j] = ox; } } } } else { if (it.isOutputDouble()) { while (it.hasNext()) { for (int j = 0; j < is; j++) { final double ix = da.getElementDoubleAbs(it.aIndex + j); double ox; ox = (Math.tan(ix)); oaf64data[it.oIndex + j] = ox; } } } else { while (it.hasNext()) { for (int j = 0; j < is; j++) { final long ix = da.getElementLongAbs(it.aIndex + j); double ox; ox = (Math.tan(ix)); oaf64data[it.oIndex + j] = ox; } } } } break; case Dataset.COMPLEX64: final float[] oc64data = ((ComplexFloatDataset) result).data; if (da.getElementsPerItem() == 1) { final double iy = 0; while (it.hasNext()) { final double ix = it.aDouble; float x; float y; float tf; float ox; float oy; x = (float) (2. * ix); y = (float) (2. * iy); tf = (float) (1. / (Math.cos(x) + Math.cosh(y))); ox = (float) (tf * Math.sin(x)); oy = (float) (tf * Math.sinh(y)); oc64data[it.oIndex] = ox; oc64data[it.oIndex + 1] = oy; } } else { while (it.hasNext()) { final double ix = it.aDouble; final double iy = da.getElementDoubleAbs(it.aIndex + 1); float x; float y; float tf; float ox; float oy; x = (float) (2. * ix); y = (float) (2. * iy); tf = (float) (1. / (Math.cos(x) + Math.cosh(y))); ox = (float) (tf * Math.sin(x)); oy = (float) (tf * Math.sinh(y)); oc64data[it.oIndex] = ox; oc64data[it.oIndex + 1] = oy; } } break; case Dataset.COMPLEX128: final double[] oc128data = ((ComplexDoubleDataset) result).data; if (da.getElementsPerItem() == 1) { final double iy = 0; while (it.hasNext()) { final double ix = it.aDouble; double x; double y; double tf; double ox; double oy; x = (2. * ix); y = (2. * iy); tf = (1. / (Math.cos(x) + Math.cosh(y))); ox = (tf * Math.sin(x)); oy = (tf * Math.sinh(y)); oc128data[it.oIndex] = ox; oc128data[it.oIndex + 1] = oy; } } else { while (it.hasNext()) { final double ix = it.aDouble; final double iy = da.getElementDoubleAbs(it.aIndex + 1); double x; double y; double tf; double ox; double oy; x = (2. * ix); y = (2. * iy); tf = (1. / (Math.cos(x) + Math.cosh(y))); ox = (tf * Math.sin(x)); oy = (tf * Math.sinh(y)); oc128data[it.oIndex] = ox; oc128data[it.oIndex + 1] = oy; } } break; default: throw new IllegalArgumentException( "tan supports integer, compound integer, real, compound real, complex datasets only"); } addFunctionName(result, "tan"); return result; }