Java sin sin(int angle)

Here you can find the source of sin(int angle)

Description

sin

License

Apache License

Declaration

public static int sin(int angle) 

Method Source Code

//package com.java2s;
/**//from  ww  w. ja  va 2s  . c o m
 * Copyright 2008 - 2012
 * 
 * Licensed under the Apache License, Version 2.0 (the "License"); you may not
 * use this file except in compliance with the License. You may obtain a copy of
 * the License at
 * 
 * http://www.apache.org/licenses/LICENSE-2.0
 * 
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
 * License for the specific language governing permissions and limitations under
 * the License.
 * 
 * @project loon
 * @author cping
 * @email?javachenpeng@yahoo.com
 * @version 0.3.3
 */

public class Main {
    private static int[] sinTable = new int[] { 0, 0x8e, 0x11d, 0x1ac, 0x23b, 0x2c9, 0x358, 0x3e6, 0x474, 0x501,
            0x58e, 0x61b, 0x6a7, 0x732, 0x7bd, 0x848, 0x8d2, 0x95b, 0x9e3, 0xa6b, 0xaf1, 0xb77, 0xbfc, 0xc80, 0xd03,
            0xd86, 0xe07, 0xe87, 0xf05, 0xf83, 0x1000, 0x107b, 0x10f5, 0x116d, 0x11e4, 0x125a, 0x12cf, 0x1342,
            0x13b3, 0x1423, 0x1491, 0x14fe, 0x1569, 0x15d2, 0x163a, 0x16a0, 0x1704, 0x1767, 0x17c7, 0x1826, 0x1883,
            0x18de, 0x1937, 0x198e, 0x19e3, 0x1a36, 0x1a87, 0x1ad6, 0x1b23, 0x1b6d, 0x1bb6, 0x1bfc, 0x1c41, 0x1c83,
            0x1cc2, 0x1d00, 0x1d3b, 0x1d74, 0x1dab, 0x1ddf, 0x1e11, 0x1e41, 0x1e6f, 0x1e9a, 0x1ec2, 0x1ee8, 0x1f0c,
            0x1f2e, 0x1f4c, 0x1f69, 0x1f83, 0x1f9b, 0x1fb0, 0x1fc2, 0x1fd3, 0x1fe0, 0x1fec, 0x1ff4, 0x1ffb, 0x1ffe,
            0x2000 };

    public static int sin(int angle) {
        angle = angle % 360;
        if (angle < 0) {
            angle += 360;
        }
        if (angle <= 90) {
            return sinTable[angle];
        }
        if (angle <= 180) {
            return sinTable[180 - angle];
        }
        if (angle <= 270) {
            return -sinTable[angle - 180];
        }
        return -sinTable[360 - angle];
    }
}

Related

  1. sin(final float angle)
  2. sin(float angle)
  3. sin(float angle)
  4. sin(float n)
  5. sin(int angle)
  6. sin(int f)
  7. sin(int i)
  8. sin(Number x)
  9. sin(Short a)