2013. 3. 14. 09:18 알고리즘

다음 맵은 수익이 발생하는 맵에서는 쓸 수 없다고 이용약관에 나와있고 

네이버 맵은 그런 내용이 없는데 ...


그래서 네이버 맵을 사용할려니 이놈은 tm좌표이다 

tm좌표 이건 일본 식민지 시절때 받은거 아직 쓰고 잇단다 

어디서는 관동대지진이후 tm 좌표가 바뀌었다고 하는데 그런 자세한 것까진 모르겠고 


네이버 맵에서 네이버 지역 검색후 나오는 mapx mapy 의 좌표값을 샘플 예제에 넣고 돌리면 

경위도가 나오는 샘플 예제 소스다 



GeoTrans.zip

http://javaexpert.tistory.com/142  이쪽이 원본 소스 

http://www.androidpub.com/1318647 이쪽이 원본 소스를 좀 더 설명한 페이지


두분다 엄청 고마우신 분 ㅠㅠ




objective c 사용 소스

GeoTransPoint *oTM = [[GeoTransPoint alloc]init];

        [oTM setX:301255];

        [oTM setY:540215];

        

        GeoTrans *oGeo = [[GeoTrans alloc]init];


        GeoTransPoint *point = [oGeo convert:KATEC DST:GEO GEOIN:oTM];

       lat = [point getY] * 1E6;

    log = [point getX] * 1E6;

        NSLog(@"lat %f lng %f  %f %f",lat , log,[point getX],[point getY]);

        

        lat = [point getY];

        log = [point getX];

               

       

        [oTM release];

        [oGeo release];







//

//  GeoTrans.m

//  FEvent

//

//  Created by jinuk son on 13. 3. 14..

//  Copyright (c) 2013년 DANAL. All rights reserved.

//


#import "GeoTrans.h"

#import <math.h>

@implementation GeoTrans


-(id)init

{

    self = [super init];

    if(self)

    {

        m_arScaleFactor[GEO] = 1;

        m_arLonCenter[GEO] = 0.0;

        m_arLatCenter[GEO] = 0.0;

        m_arFalseNorthing[GEO] = 0.0;

        m_arFalseEasting[GEO] = 0.0;

        m_arMajor[GEO] = 6378137.0;

        m_arMinor[GEO] = 6356752.3142;

        

        m_arScaleFactor[KATEC] = 0.9999;//0.9999;

        //m_arLonCenter[KATEC] = 2.22529479629277; // 127.5

        m_arLonCenter[KATEC] = 2.23402144255274; // 128

        m_arLatCenter[KATEC] = 0.663225115757845;

        m_arFalseNorthing[KATEC] = 600000.0;

        m_arFalseEasting[KATEC] = 400000.0;

        m_arMajor[KATEC] = 6377397.155;

        m_arMinor[KATEC] = 6356078.9633422494;

        

        m_arScaleFactor[TM] = 1.0;

        //this.m_arLonCenter[TM] = 2.21656815003280; // 127

        m_arLonCenter[TM] = 2.21661859489671; // 127.+10.485 minute

        m_arLatCenter[TM] = 0.663225115757845;

        m_arFalseNorthing[TM] = 500000.0;

        m_arFalseEasting[TM] = 200000.0;

        m_arMajor[TM] = 6377397.155;

        m_arMinor[TM] = 6356078.9633422494;

        

        datum_params[0] = -146.43;

        datum_params[1] = 507.89;

        datum_params[2] = 681.46;

        

        double tmp = m_arMinor[GEO] / m_arMajor[GEO];

        m_Es[GEO] = 1.0 - tmp * tmp;

        m_Esp[GEO] = m_Es[GEO] / (1.0 - m_Es[GEO]);

        

        if (m_Es[GEO] < 0.00001) {

            m_Ind[GEO] = 1.0;

        } else {

            m_Ind[GEO] = 0.0;

        }

        

        tmp = m_arMinor[KATEC] / m_arMajor[KATEC];

        m_Es[KATEC] = 1.0 - tmp * tmp;

        m_Esp[KATEC] = m_Es[KATEC] / (1.0 - m_Es[KATEC]);

        

        if (m_Es[KATEC] < 0.00001) {

            m_Ind[KATEC] = 1.0;

        } else {

            m_Ind[KATEC] = 0.0;

        }

        

        tmp = m_arMinor[TM] / m_arMajor[TM];

        m_Es[TM] = 1.0 - tmp * tmp;

        m_Esp[TM] = m_Es[TM] / (1.0 - m_Es[TM]);

        

        if (m_Es[TM] < 0.00001) {

            m_Ind[TM] = 1.0;

        } else {

            m_Ind[TM] = 0.0;

        }

        

        [self mlfn:[self e0fn:m_Es[TM]] E1:[self e1fn:m_Es[TM]] E2:[self e2fn:m_Es[TM]] E3:[self e3fn:m_Es[TM]] E4:m_arLatCenter[TM]];

        

        

        src_m[GEO] = m_arMajor[GEO] *  [self mlfn:[self e0fn:m_Es[GEO]] E1:[self e1fn:m_Es[GEO]] E2:[self e2fn:m_Es[GEO]] E3:[self e3fn:m_Es[GEO]] E4:m_arLatCenter[GEO]];

        dst_m[GEO] = m_arMajor[GEO] *  [self mlfn:[self e0fn:m_Es[GEO]] E1:[self e1fn:m_Es[GEO]] E2:[self e2fn:m_Es[GEO]] E3:[self e3fn:m_Es[GEO]] E4:m_arLatCenter[GEO]];

        src_m[KATEC] = m_arMajor[KATEC] * [self mlfn:[self e0fn:m_Es[KATEC]] E1:[self e1fn:m_Es[KATEC]] E2:[self e2fn:m_Es[KATEC]] E3:[self e3fn:m_Es[KATEC]] E4:m_arLatCenter[KATEC]];

        dst_m[KATEC] = m_arMajor[KATEC] * [self mlfn:[self e0fn:m_Es[KATEC]] E1:[self e1fn:m_Es[KATEC]] E2:[self e2fn:m_Es[KATEC]] E3:[self e3fn:m_Es[KATEC]] E4:m_arLatCenter[KATEC]];

        src_m[TM] = m_arMajor[TM] * [self mlfn:[self e0fn:m_Es[TM]] E1:[self e1fn:m_Es[TM]] E2:[self e2fn:m_Es[TM]] E3:[self e3fn:m_Es[TM]] E4:m_arLatCenter[TM]];

        dst_m[TM] = m_arMajor[TM] * [self mlfn:[self e0fn:m_Es[TM]] E1:[self e1fn:m_Es[TM]] E2:[self e2fn:m_Es[TM]] E3:[self e3fn:m_Es[TM]] E4:m_arLatCenter[TM]];


    }

    return self;

    

}


-(void)initValue {

    

 }


-(double)D2R:(double) degree {

    return degree* M_PI / 180.0;

}


-(double)R2D:(double) radian {

    return radian * 180.0 / M_PI;

}


-(double)e0fn:(double) x {

    return 1.0 - 0.25 * x * (1.0 + x / 16.0 * (3.0 + 1.25 * x));

}


-(double)e1fn:(double) x {

    return 0.375 * x * (1.0 + 0.25 * x * (1.0 + 0.46875 * x));

}


-(double)e2fn:(double) x {

    return 0.05859375 * x * x * (1.0 + 0.75 * x);

}


-(double)e3fn:(double) x {

    return x * x * x * (35.0 / 3072.0);

}


-(double)mlfn:(double) e0  E1:(double) e1 E2:(double) e2 E3:(double)e3 E4:( double) phi

{

    return e0 * phi - e1 * sin(2.0 * phi) + e2 * sin(4.0 * phi) - e3 * sin(6.0 * phi);

}


-(double)asinz:(double) value {

    if (abs(value) > 1.0) value = (value > 0 ? 1: -1);

    return asin(value);

}


-(GeoTransPoint *) convert:(int) srctype DST:(int)dsttype GEOIN:(GeoTransPoint*) in_pt{

    GeoTransPoint *tmpPt = [[GeoTransPoint alloc]init];

    GeoTransPoint *out_pt = [[[GeoTransPoint alloc]init] autorelease];

    

    

    if (srctype == GEO) {

        tmpPt.x = [self D2R:in_pt.x];

        tmpPt.y = [self D2R:in_pt.y];

    } else {


        [self tm2geo:srctype GEOIN:in_pt GEOOUT:tmpPt];

    }

    

    if (dsttype == GEO) {

        out_pt.x = [self R2D:tmpPt.x];

        out_pt.y = [self R2D:tmpPt.y];

    } else {


        [self geo2tm:dsttype GEOIN:tmpPt GEOOUT:out_pt];

        //out_pt.x = Math.round(out_pt.x);

        //out_pt.y = Math.round(out_pt.y);

    }

    [tmpPt release];

    return out_pt;

}


-(void) geo2tm:(int) dsttype  GEOIN:(GeoTransPoint *)in_pt GEOOUT:(GeoTransPoint *)out_pt {

    double x, y;

    



    [self transform:GEO DST:dsttype GEOPOINT:in_pt];

    double delta_lon = in_pt.x - m_arLonCenter[dsttype];

    double sin_phi = sin(in_pt.y);

    double cos_phi = cos(in_pt.y);

    

    if (m_Ind[dsttype] != 0) {

        double b = cos_phi * sin(delta_lon);

        

        if ((abs(abs(b) - 1.0)) < EPSLN) {

            //Log.d("무한대 에러");

            //System.out.println("무한대 에러");

        }

    } else {

        double b = 0;

        x = 0.5 * m_arMajor[dsttype] * m_arScaleFactor[dsttype] * log((1.0 + b) / (1.0 - b));

        double con = acos(cos_phi * cos(delta_lon) / sqrt(1.0 - b * b));

        

        if (in_pt.y < 0) {

            con = con * -1;

            y = m_arMajor[dsttype] * m_arScaleFactor[dsttype] * (con - m_arLatCenter[dsttype]);

        }

    }

    

    double al = cos_phi * delta_lon;

    double als = al * al;

    double c = m_Esp[dsttype] * cos_phi * cos_phi;

    double tq = tan(in_pt.y);

    double t = tq * tq;

    double con = 1.0 - m_Es[dsttype] * sin_phi * sin_phi;

    double n = m_arMajor[dsttype] / sqrt(con);

    double ml = m_arMajor[dsttype] * [self mlfn:[self e0fn:m_Es[dsttype]] E1:[self e1fn:m_Es[dsttype]] E2:[self e2fn:m_Es[dsttype]] E3:[self e3fn:m_Es[dsttype]] E4: in_pt.y];

    

    

    

    

    

    out_pt.x = m_arScaleFactor[dsttype] * n * al * (1.0 + als / 6.0 * (1.0 - t + c + als / 20.0 * (5.0 - 18.0 * t + t * t + 72.0 * c - 58.0 * m_Esp[dsttype]))) + m_arFalseEasting[dsttype];

    out_pt.y = m_arScaleFactor[dsttype] * (ml - dst_m[dsttype] + n * tq * (als * (0.5 + als / 24.0 * (5.0 - t + 9.0 * c + 4.0 * c * c + als / 30.0 * (61.0 - 58.0 * t + t * t + 600.0 * c - 330.0 * m_Esp[dsttype]))))) + m_arFalseNorthing[dsttype];

}



-(void) tm2geo:(int)srctype GEOIN:(GeoTransPoint *)in_pt GEOOUT:(GeoTransPoint *)out_pt{

    

    

    GeoTransPoint *tmpPt = [[ GeoTransPoint alloc]init];

    

    [tmpPt GeoTransPoint2:[in_pt getX] Y:[in_pt getY]];

    

    int max_iter = 6;

    

    

    if (m_Ind[srctype] != 0) {

        double f = exp(in_pt.x / (m_arMajor[srctype] * m_arScaleFactor[srctype]));

        double g = 0.5 * (f - 1.0 / f);

        double temp = m_arLatCenter[srctype] + tmpPt.y / (m_arMajor[srctype] * m_arScaleFactor[srctype]);

        double h = cos(temp);

        double con = sqrt((1.0 - h * h) / (1.0 + g * g));

        out_pt.y = [self asinz:con];


        

        if (temp < 0) out_pt.y *= -1;

        

        if ((g == 0) && (h == 0)) {

            out_pt.x = m_arLonCenter[srctype];

        } else {

            out_pt.x = atan(g / h) + m_arLonCenter[srctype];

        }

    }

    

    tmpPt.x -= m_arFalseEasting[srctype];

    tmpPt.y -= m_arFalseNorthing[srctype];

    

    double con = (src_m[srctype] + tmpPt.y / m_arScaleFactor[srctype]) / m_arMajor[srctype];

    double phi = con;

    

    int i = 0;

    

    while (true) {

        double delta_Phi = ((con + [self e1fn:m_Es[srctype]] * sin(2.0 * phi) - [self e2fn:m_Es[srctype]] * sin(4.0 * phi) + [self e3fn:m_Es[srctype]] * sin(6.0 * phi)) / [self e0fn:m_Es[srctype]]) - phi;

        phi = phi + delta_Phi;

        

        if (abs(delta_Phi) <= EPSLN) break;

        

        if (i >= max_iter) {

            //Log.d("무한대 에러");

            //System.out.println("무한대 에러");

            break;

        }

        

        i++;

    }

    

    if (abs(phi) < (M_PI / 2)) {

        double sin_phi = sin(phi);

        double cos_phi = cos(phi);

        double tan_phi = tan(phi);

        double c = m_Esp[srctype] * cos_phi * cos_phi;

        double cs = c * c;

        double t = tan_phi * tan_phi;

        double ts = t * t;

        double cont = 1.0 - m_Es[srctype] * sin_phi * sin_phi;

        double n = m_arMajor[srctype] / sqrt(cont);

        double r = n * (1.0 - m_Es[srctype]) / cont;

        double d = tmpPt.x / (n * m_arScaleFactor[srctype]);

        double ds = d * d;

        out_pt.y = phi - (n * tan_phi * ds / r) * (0.5 - ds / 24.0 * (5.0 + 3.0 * t + 10.0 * c - 4.0 * cs - 9.0 * m_Esp[srctype] - ds / 30.0 * (61.0 + 90.0 * t + 298.0 * c + 45.0 * ts - 252.0 * m_Esp[srctype] - 3.0 * cs)));

        out_pt.x = m_arLonCenter[srctype] + (d * (1.0 - ds / 6.0 * (1.0 + 2.0 * t + c - ds / 20.0 * (5.0 - 2.0 * c + 28.0 * t - 3.0 * cs + 8.0 * m_Esp[srctype] + 24.0 * ts))) / cos_phi);

    } else {

        out_pt.y = M_PI * 0.5 * sin(tmpPt.y);

        out_pt.x = m_arLonCenter[srctype];

    }


    [self transform:srctype DST:GEO GEOPOINT:out_pt];

}


-(double)getDistancebyGeo:(GeoTransPoint *) pt1  GEO2:(GeoTransPoint *) pt2 {

    double lat1 = [self D2R:pt1.y];

    double lon1 = [self D2R:pt1.x];

    double lat2 = [self D2R:pt2.y];

    double lon2 = [self D2R:pt2.x];

    

    double longitude = lon2 - lon1;

    double latitude = lat2 - lat1;

    

    double a = pow(sin(latitude / 2.0), 2) + cos(lat1) * cos(lat2) * pow(sin(longitude / 2.0), 2);

    return 6376.5 * 2.0 * atan2(sqrt(a), sqrt(1.0 - a));

}


-(double)getDistancebyKatec:(GeoTransPoint *) pt1  GEO2:(GeoTransPoint *) pt2 {

   

    pt1 =  [self convert:KATEC DST:GEO GEOIN:pt1];

    pt2 =  [self convert:KATEC DST:GEO GEOIN:pt2];

    

    return [self getDistancebyGeo:pt1 GEO2:pt2];

}


-(double)getDistancebyTm:(GeoTransPoint *) pt1  GEO2:(GeoTransPoint *) pt2 {

      

    

    pt1 =  [self convert:TM DST:GEO GEOIN:pt1];

    pt2 =  [self convert:TM DST:GEO GEOIN:pt2];

    

    return [self getDistancebyGeo:pt1 GEO2:pt2];


    

    

}


-(long) getTimebySec:(double) distance {

    return round(3600 * distance / 4);

}


-(long) getTimebyMin:(double) distance {

    return (long)(ceil(    [self getTimebySec:distance] / 60));


}


/*

 Author:       Richard Greenwood rich@greenwoodmap.com

 License:      LGPL as per: http://www.gnu.org/copyleft/lesser.html

 */


/**

 * convert between geodetic coordinates (longitude, latitude, height)

 * and gecentric coordinates (X, Y, Z)

 * ported from Proj 4.9.9 geocent.c

 */


// following constants from geocent.c

double HALF_PI = 0.5 * M_PI;

double COS_67P5  = 0.38268343236508977;  /* cosine of 67.5 degrees */

double AD_C      = 1.0026000 ;

/* Toms region 1 constant */


-(void) transform:(int)srctype DST:(int)dsttype GEOPOINT:(GeoTransPoint *) point {

    if (srctype == dsttype)

        return;

    

    if (srctype != 0 || dsttype != 0) {

        // Convert to geocentric coordinates.

        [self geodetic_to_geocentric:srctype GEOPOINT:point];


        

        // Convert between datums

        if (srctype != 0) {

            [self geocentric_to_wgs84:point];

        }

        

        if (dsttype != 0) {


            [self geocentric_from_wgs84:point];

        }

        

        // Convert back to geodetic coordinates


        [self geocentric_to_geodetic:dsttype GEOPOINT:point];

    }

}


-(Boolean) geodetic_to_geocentric:(int) type  GEOPOINT:(GeoTransPoint *) p {

    

    /*

     * The function Convert_Geodetic_To_Geocentric converts geodetic coordinates

     * (latitude, longitude, and height) to geocentric coordinates (X, Y, Z),

     * according to the current ellipsoid parameters.

     *

     *    Latitude  : Geodetic latitude in radians                     (input)

     *    Longitude : Geodetic longitude in radians                    (input)

     *    Height    : Geodetic height, in meters                       (input)

     *    X         : Calculated Geocentric X coordinate, in meters    (output)

     *    Y         : Calculated Geocentric Y coordinate, in meters    (output)

     *    Z         : Calculated Geocentric Z coordinate, in meters    (output)

     *

     */

    

    double Longitude = p.x;

    double Latitude = p.y;

    double Height = p.z;

    double X;  // output

    double Y;

    double Z;

    

    double Rn;            /*  Earth radius at location  */

    double Sin_Lat;       /*  Math.sin(Latitude)  */

    double Sin2_Lat;      /*  Square of Math.sin(Latitude)  */

    double Cos_Lat;       /*  Math.cos(Latitude)  */

    

    /*

     ** Don't blow up if Latitude is just a little out of the value

     ** range as it may just be a rounding issue.  Also removed longitude

     ** test, it should be wrapped by Math.cos() and Math.sin().  NFW for PROJ.4, Sep/2001.

     */

    if (Latitude < -HALF_PI && Latitude > -1.001 * HALF_PI )

        Latitude = -HALF_PI ;

    else if (Latitude > HALF_PI && Latitude < 1.001 * HALF_PI )

        Latitude = HALF_PI;

    else if ((Latitude < -HALF_PI) || (Latitude > HALF_PI)) { /* Latitude out of range */

        return true;

    }

    

    /* no errors */

    if (Longitude > M_PI)

        Longitude -= (2*M_PI);

    Sin_Lat = sin(Latitude);

    Cos_Lat = cos(Latitude);

    Sin2_Lat = Sin_Lat * Sin_Lat;

    Rn = m_arMajor[type] / (sqrt(1.0e0 - m_Es[type] * Sin2_Lat));

    X = (Rn + Height) * Cos_Lat * cos(Longitude);

    Y = (Rn + Height) * Cos_Lat * sin(Longitude);

    Z = ((Rn * (1 - m_Es[type])) + Height) * Sin_Lat;

    

    p.x = X;

    p.y = Y;

    p.z = Z;

    return false;

} // cs_geodetic_to_geocentric()



/** Convert_Geocentric_To_Geodetic

 * The method used here is derived from 'An Improved Algorithm for

 * Geocentric to Geodetic Coordinate Conversion', by Ralph Toms, Feb 1996

 */

-(void) geocentric_to_geodetic :(int) type GEOPOINT:(GeoTransPoint *) p {

    

    double X = p.x;

    double Y = p.y;

    double Z = p.z;

    double Longitude;

    double Latitude = 0.;

    double Height;

    

    double W;        /* distance from Z axis */

    double W2;       /* square of distance from Z axis */

    double T0;       /* initial estimate of vertical component */

    double T1;       /* corrected estimate of vertical component */

    double S0;       /* initial estimate of horizontal component */

    double S1;       /* corrected estimate of horizontal component */

    double Sin_B0;   /* Math.sin(B0), B0 is estimate of Bowring aux doubleiable */

    double Sin3_B0;  /* cube of Math.sin(B0) */

    double Cos_B0;   /* Math.cos(B0) */

    double Sin_p1;   /* Math.sin(phi1), phi1 is estimated latitude */

    double Cos_p1;   /* Math.cos(phi1) */

    double Rn;       /* Earth radius at location */

    double Sum;      /* numerator of Math.cos(phi1) */

    Boolean At_Pole;  /* indicates location is in polar region */

    

    At_Pole = false;

    if (X != 0.0) {

        Longitude = atan2(Y,X);

    }

    else {

        if (Y > 0) {

            Longitude = HALF_PI;

        }

        else if (Y < 0) {

            Longitude = -HALF_PI;

        }

        else {

            At_Pole = true;

            Longitude = 0.0;

            if (Z > 0.0) {  /* north pole */

                Latitude = HALF_PI;

            }

            else if (Z < 0.0) {  /* south pole */

                Latitude = -HALF_PI;

            }

            else {  /* center of earth */

                Latitude = HALF_PI;

                Height = -m_arMinor[type];

                return;

            }

        }

    }

    W2 = X*X + Y*Y;

    W = sqrt(W2);

    T0 = Z * AD_C;

    S0 = sqrt(T0 * T0 + W2);

    Sin_B0 = T0 / S0;

    Cos_B0 = W / S0;

    Sin3_B0 = Sin_B0 * Sin_B0 * Sin_B0;

    T1 = Z + m_arMinor[type] * m_Esp[type] * Sin3_B0;

    Sum = W - m_arMajor[type] * m_Es[type] * Cos_B0 * Cos_B0 * Cos_B0;

    S1 = sqrt(T1*T1 + Sum * Sum);

    Sin_p1 = T1 / S1;

    Cos_p1 = Sum / S1;

    Rn = m_arMajor[type] / sqrt(1.0 - m_Es[type] * Sin_p1 * Sin_p1);

    if (Cos_p1 >= COS_67P5) {

        Height = W / Cos_p1 - Rn;

    }

    else if (Cos_p1 <= -COS_67P5) {

        Height = W / -Cos_p1 - Rn;

    }

    else {

        Height = Z / Sin_p1 + Rn * (m_Es[type] - 1.0);

    }

    if (At_Pole == false) {

        Latitude = atan(Sin_p1 / Cos_p1);

    }

    

    p.x = Longitude;

    p.y =Latitude;

    p.z = Height;

    return;

} // geocentric_to_geodetic()




/****************************************************************/

// geocentic_to_wgs84(defn, p )

//  defn = coordinate system definition,

//  p = point to transform in geocentric coordinates (x,y,z)

-(void) geocentric_to_wgs84:(GeoTransPoint *) p {

    

    //if( defn.datum_type == PJD_3PARAM )

    {

        // if( x[io] == HUGE_VAL )

        //    continue;

        p.x += datum_params[0];

        p.y += datum_params[1];

        p.z += datum_params[2];

    }

} // geocentric_to_wgs84


/****************************************************************/

// geocentic_from_wgs84()

//  coordinate system definition,

//  point to transform in geocentric coordinates (x,y,z)

-(void) geocentric_from_wgs84:(GeoTransPoint *) p {

    

    //if( defn.datum_type == PJD_3PARAM )

    {

        //if( x[io] == HUGE_VAL )

        //    continue;

        p.x -= datum_params[0];

        p.y -= datum_params[1];

        p.z -= datum_params[2];

        

    }

} //geocentric_from_wgs84()

@end



//

//  GeoTrans.h

//  FEvent

//

//  Created by jinuk son on 13. 3. 14..

//  Copyright (c) 2013년 DANAL. All rights reserved.

//

#import <Foundation/Foundation.h>

#import "GeoTransPoint.h"

#define GEO 0

#define KATEC 1

#define TM 2

#define GRS80 3

#define EPSLN 0.0000000001


@interface GeoTrans : NSObject

{

    

    

    double m_Ind [3];

double m_Es [3];

double m_Esp [3];

double src_m [3];

double dst_m [3];

    


double m_arMajor [3];

double m_arMinor [3];

    

double m_arScaleFactor [3];

double m_arLonCenter [3];

double m_arLatCenter [3];

double m_arFalseNorthing [3];

double m_arFalseEasting [3];

double datum_params [3];


}

-(void)initValue;

-(GeoTransPoint *) convert:(int) srctype DST:(int)dsttype GEOIN:(GeoTransPoint*) in_pt;

@end

//

//  GeoTransPoint.m

//  FEvent

//

//  Created by jinuk son on 13. 3. 14..

//  Copyright (c) 2013년 DANAL. All rights reserved.

//


#import "GeoTransPoint.h"

@implementation GeoTransPoint

@synthesize x,y,z;

-(void) GeoTransPoint2:(double) _x Y:(double) _y

{

    

    x = _x;

    y = _y;

    z = 0;

}

-(void) GeoTransPoint3:(double) _x Y:(double) _y Z:(double)_z {

    

    x = _x;

    y = _y;

    z = 0;

}

-(double) getX {

    return x;

}


-(double) getY {

    return y;

}

@end

//

//  GeoTransPoint.h

//  FEvent

//

//  Created by jinuk son on 13. 3. 14..

//  Copyright (c) 2013년 DANAL. All rights reserved.

//

#import <Foundation/Foundation.h>


@interface GeoTransPoint : NSObject

{


    

}

@property(nonatomic,readwrite)double x;

@property(nonatomic,readwrite)double y;

@property(nonatomic,readwrite)double z;


-(void) GeoTransPoint2:(double) _x Y:(double) _y;

-(void) GeoTransPoint3:(double) _x Y:(double) _y Z:(double)_z ;

-(double) getX;

-(double) getY ;


@end


'알고리즘' 카테고리의 다른 글

gson 읽고 쓰기 java  (0) 2013.03.08
java des algorithm (자바 DES 알고리즘)  (0) 2011.07.25
barcode 128a 소스 (java,c 사용가능)  (0) 2011.07.13
swap  (0) 2011.04.27
도스명령어 년 월 일  (0) 2010.03.24
posted by 욱이다
2013. 3. 8. 09:30 알고리즘

라이브러리 다운


gson guide



GsonTest.zip





import java.util.ArrayList;


import com.google.gson.Gson;


public class MainTest {


public static void main(String[] args) {


MainTest maint = new MainTest();


}


public MainTest() {

load l = new load();

Gson gson = new Gson();

String aaa = gson.toJson(l);

System.out.println(aaa);


String source = "{\"KoreanAnswerInfo\":{\"list_total_count\":4,\"row\":[{\"Q_NAME\":\"다음에서 '가라뜨다'의 뜻은?\",\"Q_OPEN\":2.0130306E7,\"A_SEQ\":689,\"Q_SEQ\":167,\"A_NAME\":\"눈을 아래로 향하여 뜨다\",\"A_CORRECT\":\"정답\"},{\"Q_NAME\":\"다음에서 '가라뜨다'의 뜻은?\",\"Q_OPEN\":2.0130306E7,\"A_SEQ\":690,\"Q_SEQ\":167,\"A_NAME\":\"물 위에 있는 것을 골라서 뜨다\",\"A_CORRECT\":\"\"},{\"Q_NAME\":\"다음에서 '가라뜨다'의 뜻은?\",\"Q_OPEN\":2.0130306E7,\"A_SEQ\":691,\"Q_SEQ\":167,\"A_NAME\":\"옳고 그름을 분명히 가려내다\",\"A_CORRECT\":\"\"},{\"Q_NAME\":\"다음에서 '가라뜨다'의 뜻은?\",\"Q_OPEN\":2.0130306E7,\"A_SEQ\":692,\"Q_SEQ\":167,\"A_NAME\":\"몹시 화가 나서 소리를 지르다\",\"A_CORRECT\":\"\"}]}}";

System.out.println(source);

l = gson.fromJson(source, load.class);

l.KoreanAnswerInfo.print();

}


class load {

private final KoreanAnswerInfoClass KoreanAnswerInfo;


public load() {

KoreanAnswerInfo = new KoreanAnswerInfoClass();

}


class KoreanAnswerInfoClass {

public void print()

{

System.out.println("list_total_count "+list_total_count);

for( int i = 0 ; i < row.size(); i ++)

{

row.get(i).print();

}

}

private final int list_total_count;


ArrayList<RowData> row = new ArrayList<MainTest.load.KoreanAnswerInfoClass.RowData>();

public KoreanAnswerInfoClass() {

this.list_total_count = 4;

row.add(new RowData("qname","qopen","aseq","qseq","aname","acorrect"));

row.add(new RowData("qname1","qopen1","aseq1","qseq1","aname1","acorrect1"));

}

class RowData

{

String Q_NAME;

String Q_OPEN;

String A_SEQ;

String Q_SEQ;

String A_NAME;

String A_CORRECT;

public RowData(String qname , String qopen, String aseq, String qseq, String aname, String acorrect)

{

Q_NAME = qname;

Q_OPEN = qopen;

A_SEQ = aseq;

Q_SEQ = qseq;

A_NAME = aname;

A_CORRECT = acorrect;

}

public void print()

{

System.out.println(Q_NAME +" "+ Q_OPEN+" "+ A_SEQ+" "+ Q_SEQ+" "+ A_NAME+" "+ A_CORRECT);

}

}

}


}


}



'알고리즘' 카테고리의 다른 글

MapView 경위도 tm 카텍 변환 알고리즘  (0) 2013.03.14
java des algorithm (자바 DES 알고리즘)  (0) 2011.07.25
barcode 128a 소스 (java,c 사용가능)  (0) 2011.07.13
swap  (0) 2011.04.27
도스명령어 년 월 일  (0) 2010.03.24
posted by 욱이다
2011. 7. 25. 10:38 알고리즘

//////////////////////////////////////////////////
DesLibrary des = new DesLibrary("12345678".getBytes());
   
   String message = "가나다라마바사아자차카타파하하하으에으ㅔ으에흥";
   
   byte buf []= new byte[((message.getBytes().length/8) + 1) *8];
   byte getbuf1[],getbuf2[];
   

   System.arraycopy(message.getBytes(), 0, buf, 0, message.getBytes().length);
   
   System.out.println(new String(buf));
   
   //암호화한다
   getbuf1 = des.encrypt(buf);
   System.out.println(new String(getbuf1));
   
   //복호화한다
   getbuf2 = des.decrypt(getbuf1);
   System.out.println(new String(getbuf2));


//////////////////////////////////////////////////


import java.io.*;

/**
 * This code is derived from the above source
 * JCIFS API
 * Norbert Hranitzky
 *
 * <p>and modified again by Michael B. Allen
 */

public class DesLibrary   {


    private int[] encryptKeys = new int[32];
    private int[] decryptKeys = new int[32];

    private int[] tempInts = new int[2];


    public DesLibrary( ) {

    }

    // Constructor, byte-array key.
    public DesLibrary( byte[] key )    {
        if( key.length == 7 ) {
            byte[] key8 = new byte[8];
            makeSMBKey( key, key8 );
            setKey( key8 );
        } else {
            setKey( key );
        }
    }


    public static void makeSMBKey(byte[] key7, byte[] key8) {

        int i;

        key8[0] = (byte) ( ( key7[0] >> 1) & 0xff);
        key8[1] = (byte)(( ((key7[0] & 0x01) << 6) | (((key7[1] & 0xff)>>2) & 0xff)) & 0xff );
        key8[2] = (byte)(( ((key7[1] & 0x03) << 5) | (((key7[2] & 0xff)>>3) & 0xff)) & 0xff );
        key8[3] = (byte)(( ((key7[2] & 0x07) << 4) | (((key7[3] & 0xff)>>4) & 0xff)) & 0xff );
        key8[4] = (byte)(( ((key7[3] & 0x0F) << 3) | (((key7[4] & 0xff)>>5) & 0xff)) & 0xff );
        key8[5] = (byte)(( ((key7[4] & 0x1F) << 2) | (((key7[5] & 0xff)>>6) & 0xff)) & 0xff );
        key8[6] = (byte)(( ((key7[5] & 0x3F) << 1) | (((key7[6] & 0xff)>>7) & 0xff)) & 0xff );
        key8[7] = (byte)(key7[6] & 0x7F);
        for (i=0;i<8;i++) {
            key8[i] = (byte)( key8[i] << 1);
        }
    }

    /// Set the key.
    public void setKey( byte[] key ) {

        // CHECK PAROTY TBD
        deskey( key, true, encryptKeys );
        deskey( key, false, decryptKeys );
    }

    // Turn an 8-byte key into internal keys.
    private void deskey( byte[] keyBlock, boolean encrypting, int[] KnL ) {

        int i, j, l, m, n;
        int[] pc1m = new int[56];
        int[] pcr  = new int[56];
        int[] kn   = new int[32];

        for ( j = 0; j < 56; ++j )  {
            l       = pc1[j];
            m       = l & 07;
            pc1m[j] = ( (keyBlock[l >>> 3] & bytebit[m]) != 0 )? 1: 0;
        }

        for ( i = 0; i < 16; ++i ) {

            if ( encrypting )
                m = i << 1;
            else
                m = (15-i) << 1;
            n = m+1;
            kn[m] = kn[n] = 0;
            for ( j = 0; j < 28; ++j ) {
                l = j+totrot[i];
                if ( l < 28 )
                    pcr[j] = pc1m[l];
                else
                    pcr[j] = pc1m[l-28];
            }
            for ( j=28; j < 56; ++j ) {
                l = j+totrot[i];
                if ( l < 56 )
                    pcr[j] = pc1m[l];
                else
                    pcr[j] = pc1m[l-28];
            }
            for ( j = 0; j < 24; ++j ) {
                if ( pcr[pc2[j]] != 0 )
                    kn[m] |= bigbyte[j];
                if ( pcr[pc2[j+24]] != 0 )
                    kn[n] |= bigbyte[j];
            }
        }
        cookey( kn, KnL );
    }

    private void cookey( int[] raw, int KnL[] )     {
        int raw0, raw1;
        int rawi, KnLi;
        int i;

        for ( i = 0, rawi = 0, KnLi = 0; i < 16; ++i )   {
            raw0 = raw[rawi++];
            raw1 = raw[rawi++];
            KnL[KnLi]  = (raw0 & 0x00fc0000) <<   6;
            KnL[KnLi] |= (raw0 & 0x00000fc0) <<  10;
            KnL[KnLi] |= (raw1 & 0x00fc0000) >>> 10;
            KnL[KnLi] |= (raw1 & 0x00000fc0) >>>  6;
            ++KnLi;
            KnL[KnLi]  = (raw0 & 0x0003f000) <<  12;
            KnL[KnLi] |= (raw0 & 0x0000003f) <<  16;
            KnL[KnLi] |= (raw1 & 0x0003f000) >>>  4;
            KnL[KnLi] |= (raw1 & 0x0000003f);
            ++KnLi;
        }
    }


    /// Encrypt a block of eight bytes.
    private void encrypt( byte[] clearText, int clearOff, byte[] cipherText, int cipherOff ) {

        squashBytesToInts( clearText, clearOff, tempInts, 0, 2 );
        des( tempInts, tempInts, encryptKeys );
        spreadIntsToBytes( tempInts, 0, cipherText, cipherOff, 2 );
    }

    /// Decrypt a block of eight bytes.
    private void decrypt( byte[] cipherText, int cipherOff, byte[] clearText, int clearOff ) {

        squashBytesToInts( cipherText, cipherOff, tempInts, 0, 2 );
        des( tempInts, tempInts, decryptKeys );
        spreadIntsToBytes( tempInts, 0, clearText, clearOff, 2 );
    }

    // The DES function.
    private void des( int[] inInts, int[] outInts, int[] keys ) {

        int fval, work, right, leftt;
        int round;
        int keysi = 0;

        leftt = inInts[0];
        right = inInts[1];

        work   = ((leftt >>>  4) ^ right) & 0x0f0f0f0f;
        right ^= work;
        leftt ^= (work << 4);

        work   = ((leftt >>> 16) ^ right) & 0x0000ffff;
        right ^= work;
        leftt ^= (work << 16);

        work   = ((right >>>  2) ^ leftt) & 0x33333333;
        leftt ^= work;
        right ^= (work << 2);

        work   = ((right >>>  8) ^ leftt) & 0x00ff00ff;
        leftt ^= work;
        right ^= (work << 8);
        right  = (right << 1) | ((right >>> 31) & 1);

        work   = (leftt ^ right) & 0xaaaaaaaa;
        leftt ^= work;
        right ^= work;
        leftt  = (leftt << 1) | ((leftt >>> 31) & 1);

        for ( round = 0; round < 8; ++round )  {
            work   = (right << 28) | (right >>> 4);
            work  ^= keys[keysi++];
            fval   = SP7[ work         & 0x0000003f ];
            fval  |= SP5[(work >>>  8) & 0x0000003f ];
            fval  |= SP3[(work >>> 16) & 0x0000003f ];
            fval  |= SP1[(work >>> 24) & 0x0000003f ];
            work   = right ^ keys[keysi++];
            fval  |= SP8[ work         & 0x0000003f ];
            fval  |= SP6[(work >>>  8) & 0x0000003f ];
            fval  |= SP4[(work >>> 16) & 0x0000003f ];
            fval  |= SP2[(work >>> 24) & 0x0000003f ];
            leftt ^= fval;
            work   = (leftt << 28) | (leftt >>> 4);
            work  ^= keys[keysi++];
            fval   = SP7[ work         & 0x0000003f ];
            fval  |= SP5[(work >>>  8) & 0x0000003f ];
            fval  |= SP3[(work >>> 16) & 0x0000003f ];
            fval  |= SP1[(work >>> 24) & 0x0000003f ];
            work   = leftt ^ keys[keysi++];
            fval  |= SP8[ work         & 0x0000003f ];
            fval  |= SP6[(work >>>  8) & 0x0000003f ];
            fval  |= SP4[(work >>> 16) & 0x0000003f ];
            fval  |= SP2[(work >>> 24) & 0x0000003f ];
            right ^= fval;
        }

        right  = (right << 31) | (right >>> 1);
        work   = (leftt ^ right) & 0xaaaaaaaa;
        leftt ^= work;
        right ^= work;
        leftt  = (leftt << 31) | (leftt >>> 1);
        work   = ((leftt >>>  8) ^ right) & 0x00ff00ff;
        right ^= work;
        leftt ^= (work << 8);
        work   = ((leftt >>>  2) ^ right) & 0x33333333;
        right ^= work;
        leftt ^= (work << 2);
        work   = ((right >>> 16) ^ leftt) & 0x0000ffff;
        leftt ^= work;
        right ^= (work << 16);
        work   = ((right >>>  4) ^ leftt) & 0x0f0f0f0f;
        leftt ^= work;
        right ^= (work << 4);
        outInts[0] = right;
        outInts[1] = leftt;
    }


    /// Encrypt a block of bytes.
    public void encrypt( byte[] clearText, byte[] cipherText )  {
        encrypt( clearText, 0, cipherText, 0 );
    }

    /// Decrypt a block of bytes.
    public void decrypt( byte[] cipherText, byte[] clearText ) {

        decrypt( cipherText, 0, clearText, 0 );
    }

    /**
     * encrypts an array where the length must be a multiple of 8
     */
    public byte[] encrypt(byte[] clearText) {

        int length = clearText.length;

        if (length % 8 != 0) {
            System.out.println("Array must be a multiple of 8");
            return null;
        }

        byte[] cipherText = new byte[length];
        int count = length / 8;

        for (int i=0; i<count; i++)
            encrypt(clearText, i*8, cipherText, i*8);

        return cipherText;
    }

    /**
     * decrypts an array where the length must be a multiple of 8
     */
    public byte[] decrypt(byte[] cipherText) {

        int length = cipherText.length;

        if (length % 8 != 0) {
            System.out.println("Array must be a multiple of 8");
            return null;
        }

        byte[] clearText = new byte[length];
        int count = length / 8;

        for (int i=0; i<count; i++)

//원래 이게 있는 소스인데 아랫부분을 수정해줘야지 지대로된 복호화가 가능했다


         decrypt(cipherText, i*8, clearText, i*8);
         
            //encrypt(cipherText, i*8, clearText, i*8);

        return clearText;
    }


    // Tables, permutations, S-boxes, etc.

    private static byte[] bytebit = {
        (byte)0x80, (byte)0x40, (byte)0x20, (byte)0x10,
        (byte)0x08, (byte)0x04, (byte)0x02, (byte)0x01
    };
    private static int[] bigbyte = {
        0x800000, 0x400000, 0x200000, 0x100000,
        0x080000, 0x040000, 0x020000, 0x010000,
        0x008000, 0x004000, 0x002000, 0x001000,
        0x000800, 0x000400, 0x000200, 0x000100,
        0x000080, 0x000040, 0x000020, 0x000010,
        0x000008, 0x000004, 0x000002, 0x000001
    };
    private static byte[] pc1 = {
        (byte)56, (byte)48, (byte)40, (byte)32, (byte)24, (byte)16, (byte) 8,
        (byte) 0, (byte)57, (byte)49, (byte)41, (byte)33, (byte)25, (byte)17,
        (byte) 9, (byte) 1, (byte)58, (byte)50, (byte)42, (byte)34, (byte)26,
        (byte)18, (byte)10, (byte) 2, (byte)59, (byte)51, (byte)43, (byte)35,
        (byte)62, (byte)54, (byte)46, (byte)38, (byte)30, (byte)22, (byte)14,
        (byte) 6, (byte)61, (byte)53, (byte)45, (byte)37, (byte)29, (byte)21,
        (byte)13, (byte) 5, (byte)60, (byte)52, (byte)44, (byte)36, (byte)28,
        (byte)20, (byte)12, (byte) 4, (byte)27, (byte)19, (byte)11, (byte)3
    };
    private static int[] totrot = {
        1, 2, 4, 6, 8, 10, 12, 14, 15, 17, 19, 21, 23, 25, 27, 28
    };

    private static byte[] pc2 = {
        (byte)13, (byte)16, (byte)10, (byte)23, (byte) 0, (byte) 4,
        (byte) 2, (byte)27, (byte)14, (byte) 5, (byte)20, (byte) 9,
        (byte)22, (byte)18, (byte)11, (byte)3 , (byte)25, (byte) 7,
        (byte)15, (byte) 6, (byte)26, (byte)19, (byte)12, (byte) 1,
        (byte)40, (byte)51, (byte)30, (byte)36, (byte)46, (byte)54,
        (byte)29, (byte)39, (byte)50, (byte)44, (byte)32, (byte)47,
        (byte)43, (byte)48, (byte)38, (byte)55, (byte)33, (byte)52,
        (byte)45, (byte)41, (byte)49, (byte)35, (byte)28, (byte)31,
    };

    private static int[] SP1 = {
        0x01010400, 0x00000000, 0x00010000, 0x01010404,
        0x01010004, 0x00010404, 0x00000004, 0x00010000,
        0x00000400, 0x01010400, 0x01010404, 0x00000400,
        0x01000404, 0x01010004, 0x01000000, 0x00000004,
        0x00000404, 0x01000400, 0x01000400, 0x00010400,
        0x00010400, 0x01010000, 0x01010000, 0x01000404,
        0x00010004, 0x01000004, 0x01000004, 0x00010004,
        0x00000000, 0x00000404, 0x00010404, 0x01000000,
        0x00010000, 0x01010404, 0x00000004, 0x01010000,
        0x01010400, 0x01000000, 0x01000000, 0x00000400,
        0x01010004, 0x00010000, 0x00010400, 0x01000004,
        0x00000400, 0x00000004, 0x01000404, 0x00010404,
        0x01010404, 0x00010004, 0x01010000, 0x01000404,
        0x01000004, 0x00000404, 0x00010404, 0x01010400,
        0x00000404, 0x01000400, 0x01000400, 0x00000000,
        0x00010004, 0x00010400, 0x00000000, 0x01010004
    };
    private static int[] SP2 = {
        0x80108020, 0x80008000, 0x00008000, 0x00108020,
        0x00100000, 0x00000020, 0x80100020, 0x80008020,
        0x80000020, 0x80108020, 0x80108000, 0x80000000,
        0x80008000, 0x00100000, 0x00000020, 0x80100020,
        0x00108000, 0x00100020, 0x80008020, 0x00000000,
        0x80000000, 0x00008000, 0x00108020, 0x80100000,
        0x00100020, 0x80000020, 0x00000000, 0x00108000,
        0x00008020, 0x80108000, 0x80100000, 0x00008020,
        0x00000000, 0x00108020, 0x80100020, 0x00100000,
        0x80008020, 0x80100000, 0x80108000, 0x00008000,
        0x80100000, 0x80008000, 0x00000020, 0x80108020,
        0x00108020, 0x00000020, 0x00008000, 0x80000000,
        0x00008020, 0x80108000, 0x00100000, 0x80000020,
        0x00100020, 0x80008020, 0x80000020, 0x00100020,
        0x00108000, 0x00000000, 0x80008000, 0x00008020,
        0x80000000, 0x80100020, 0x80108020, 0x00108000
    };
    private static int[] SP3 = {
        0x00000208, 0x08020200, 0x00000000, 0x08020008,
        0x08000200, 0x00000000, 0x00020208, 0x08000200,
        0x00020008, 0x08000008, 0x08000008, 0x00020000,
        0x08020208, 0x00020008, 0x08020000, 0x00000208,
        0x08000000, 0x00000008, 0x08020200, 0x00000200,
        0x00020200, 0x08020000, 0x08020008, 0x00020208,
        0x08000208, 0x00020200, 0x00020000, 0x08000208,
        0x00000008, 0x08020208, 0x00000200, 0x08000000,
        0x08020200, 0x08000000, 0x00020008, 0x00000208,
        0x00020000, 0x08020200, 0x08000200, 0x00000000,
        0x00000200, 0x00020008, 0x08020208, 0x08000200,
        0x08000008, 0x00000200, 0x00000000, 0x08020008,
        0x08000208, 0x00020000, 0x08000000, 0x08020208,
        0x00000008, 0x00020208, 0x00020200, 0x08000008,
        0x08020000, 0x08000208, 0x00000208, 0x08020000,
        0x00020208, 0x00000008, 0x08020008, 0x00020200
    };
    private static int[] SP4 = {
        0x00802001, 0x00002081, 0x00002081, 0x00000080,
        0x00802080, 0x00800081, 0x00800001, 0x00002001,
        0x00000000, 0x00802000, 0x00802000, 0x00802081,
        0x00000081, 0x00000000, 0x00800080, 0x00800001,
        0x00000001, 0x00002000, 0x00800000, 0x00802001,
        0x00000080, 0x00800000, 0x00002001, 0x00002080,
        0x00800081, 0x00000001, 0x00002080, 0x00800080,
        0x00002000, 0x00802080, 0x00802081, 0x00000081,
        0x00800080, 0x00800001, 0x00802000, 0x00802081,
        0x00000081, 0x00000000, 0x00000000, 0x00802000,
        0x00002080, 0x00800080, 0x00800081, 0x00000001,
        0x00802001, 0x00002081, 0x00002081, 0x00000080,
        0x00802081, 0x00000081, 0x00000001, 0x00002000,
        0x00800001, 0x00002001, 0x00802080, 0x00800081,
        0x00002001, 0x00002080, 0x00800000, 0x00802001,
        0x00000080, 0x00800000, 0x00002000, 0x00802080
    };
    private static int[] SP5 = {
        0x00000100, 0x02080100, 0x02080000, 0x42000100,
        0x00080000, 0x00000100, 0x40000000, 0x02080000,
        0x40080100, 0x00080000, 0x02000100, 0x40080100,
        0x42000100, 0x42080000, 0x00080100, 0x40000000,
        0x02000000, 0x40080000, 0x40080000, 0x00000000,
        0x40000100, 0x42080100, 0x42080100, 0x02000100,
        0x42080000, 0x40000100, 0x00000000, 0x42000000,
        0x02080100, 0x02000000, 0x42000000, 0x00080100,
        0x00080000, 0x42000100, 0x00000100, 0x02000000,
        0x40000000, 0x02080000, 0x42000100, 0x40080100,
        0x02000100, 0x40000000, 0x42080000, 0x02080100,
        0x40080100, 0x00000100, 0x02000000, 0x42080000,
        0x42080100, 0x00080100, 0x42000000, 0x42080100,
        0x02080000, 0x00000000, 0x40080000, 0x42000000,
        0x00080100, 0x02000100, 0x40000100, 0x00080000,
        0x00000000, 0x40080000, 0x02080100, 0x40000100
    };
    private static int[] SP6 = {
        0x20000010, 0x20400000, 0x00004000, 0x20404010,
        0x20400000, 0x00000010, 0x20404010, 0x00400000,
        0x20004000, 0x00404010, 0x00400000, 0x20000010,
        0x00400010, 0x20004000, 0x20000000, 0x00004010,
        0x00000000, 0x00400010, 0x20004010, 0x00004000,
        0x00404000, 0x20004010, 0x00000010, 0x20400010,
        0x20400010, 0x00000000, 0x00404010, 0x20404000,
        0x00004010, 0x00404000, 0x20404000, 0x20000000,
        0x20004000, 0x00000010, 0x20400010, 0x00404000,
        0x20404010, 0x00400000, 0x00004010, 0x20000010,
        0x00400000, 0x20004000, 0x20000000, 0x00004010,
        0x20000010, 0x20404010, 0x00404000, 0x20400000,
        0x00404010, 0x20404000, 0x00000000, 0x20400010,
        0x00000010, 0x00004000, 0x20400000, 0x00404010,
        0x00004000, 0x00400010, 0x20004010, 0x00000000,
        0x20404000, 0x20000000, 0x00400010, 0x20004010
    };
    private static int[] SP7 = {
        0x00200000, 0x04200002, 0x04000802, 0x00000000,
        0x00000800, 0x04000802, 0x00200802, 0x04200800,
        0x04200802, 0x00200000, 0x00000000, 0x04000002,
        0x00000002, 0x04000000, 0x04200002, 0x00000802,
        0x04000800, 0x00200802, 0x00200002, 0x04000800,
        0x04000002, 0x04200000, 0x04200800, 0x00200002,
        0x04200000, 0x00000800, 0x00000802, 0x04200802,
        0x00200800, 0x00000002, 0x04000000, 0x00200800,
        0x04000000, 0x00200800, 0x00200000, 0x04000802,
        0x04000802, 0x04200002, 0x04200002, 0x00000002,
        0x00200002, 0x04000000, 0x04000800, 0x00200000,
        0x04200800, 0x00000802, 0x00200802, 0x04200800,
        0x00000802, 0x04000002, 0x04200802, 0x04200000,
        0x00200800, 0x00000000, 0x00000002, 0x04200802,
        0x00000000, 0x00200802, 0x04200000, 0x00000800,
        0x04000002, 0x04000800, 0x00000800, 0x00200002
    };
    private static int[] SP8 = {
        0x10001040, 0x00001000, 0x00040000, 0x10041040,
        0x10000000, 0x10001040, 0x00000040, 0x10000000,
        0x00040040, 0x10040000, 0x10041040, 0x00041000,
        0x10041000, 0x00041040, 0x00001000, 0x00000040,
        0x10040000, 0x10000040, 0x10001000, 0x00001040,
        0x00041000, 0x00040040, 0x10040040, 0x10041000,
        0x00001040, 0x00000000, 0x00000000, 0x10040040,
        0x10000040, 0x10001000, 0x00041040, 0x00040000,
        0x00041040, 0x00040000, 0x10041000, 0x00001000,
        0x00000040, 0x10040040, 0x00001000, 0x00041040,
        0x10001000, 0x00000040, 0x10000040, 0x10040000,
        0x10040040, 0x10000000, 0x00040000, 0x10001040,
        0x00000000, 0x10041040, 0x00040040, 0x10000040,
        0x10040000, 0x10001000, 0x10001040, 0x00000000,
        0x10041040, 0x00041000, 0x00041000, 0x00001040,
        0x00001040, 0x00040040, 0x10000000, 0x10041000
    };


 /// Squash bytes down to ints.
    public static void squashBytesToInts( byte[] inBytes, int inOff, int[] outInts,
                                           int outOff, int intLen ) {

        for ( int i = 0; i < intLen; ++i )
            outInts[outOff + i] =
                ( ( inBytes[inOff + i * 4    ] & 0xff ) << 24 ) |
                ( ( inBytes[inOff + i * 4 + 1] & 0xff ) << 16 ) |
                ( ( inBytes[inOff + i * 4 + 2] & 0xff ) <<  8 ) |
                 ( inBytes[inOff + i * 4 + 3] & 0xff );
    }

    /// Spread ints into bytes.
    public static void spreadIntsToBytes( int[] inInts, int inOff, byte[] outBytes,
                                         int outOff, int intLen ) {

        for ( int i = 0; i < intLen; ++i ) {

            outBytes[outOff + i * 4    ] = (byte) ( inInts[inOff + i] >>> 24 );
            outBytes[outOff + i * 4 + 1] = (byte) ( inInts[inOff + i] >>> 16 );
            outBytes[outOff + i * 4 + 2] = (byte) ( inInts[inOff + i] >>>  8 );
            outBytes[outOff + i * 4 + 3] = (byte)   inInts[inOff + i];
        }
    }
}

'알고리즘' 카테고리의 다른 글

MapView 경위도 tm 카텍 변환 알고리즘  (0) 2013.03.14
gson 읽고 쓰기 java  (0) 2013.03.08
barcode 128a 소스 (java,c 사용가능)  (0) 2011.07.13
swap  (0) 2011.04.27
도스명령어 년 월 일  (0) 2010.03.24
posted by 욱이다
2011. 7. 13. 13:46 알고리즘

참고 : http://www.codeproject.com/KB/graphics/BarcodeLibrary.aspx
참고: http://www.codeproject.com/KB/cpp/includeh10.aspx
위의 주소에 보면 비쥬얼 스튜디오로 돌려 볼수있게 잘되어있다
모든 바코드 소스를 확인해볼수있다

아래의 코드는 참고 사이트에서 코드를 참고한것이다
내가 사용할 128a만 뽑아서
원래는 wipic용으로 만들었다가 다시 플랫폼이 변경되서
wipijava용으로 변경한것이다



import org.kwis.msp.lcdui.Graphics;

public class BarcodeClass {

 int ga2_Code128[][] = {
   { 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79,
     80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94,
     95, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15,
     16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30,
     31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45,
     46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60,
     61, 62, 63, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
     -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
     -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
     -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
     -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
     -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
     -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 95, 96, 97,
     98, 99, 100, 101, 102, 103, 104, 105, 106, },
   { -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
     -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
     -1, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15,
     16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30,
     31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45,
     46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60,
     61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75,
     76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90,
     91, 92, 93, 94, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
     -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
     -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
     -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
     -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 95, 96, 97,
     98, 99, 100, 101, 102, 103, 104, 105, 106, } };

 int ch[] = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17,
   18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34,
   35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51,
   52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68,
   69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85,
   86, 87, 88, 89, 90, 91, 92, 93, 94, 95, 96, 97, 98, 99, 100, 101,
   102, 103, 104, 105, 106 };

 String psz[] = { "bbsbbssbbss", "bbssbbsbbss", "bbssbbssbbs",
   "bssbssbbsss", "bssbsssbbss", "bsssbssbbss", "bssbbssbsss",
   "bssbbsssbss", "bsssbbssbss", "bbssbssbsss", "bbssbsssbss",
   "bbsssbssbss", "bsbbssbbbss", "bssbbsbbbss", "bssbbssbbbs",
   "bsbbbssbbss", "bssbbbsbbss", "bssbbbssbbs", "bbssbbbssbs",
   "bbssbsbbbss", "bbssbssbbbs", "bbsbbbssbss", "bbssbbbsbss",
   "bbbsbbsbbbs", "bbbsbssbbss", "bbbssbsbbss", "bbbssbssbbs",
   "bbbsbbssbss", "bbbssbbsbss", "bbbssbbssbs", "bbsbbsbbsss",
   "bbsbbsssbbs", "bbsssbbsbbs", "bsbsssbbsss", "bsssbsbbsss",
   "bsssbsssbbs", "bsbbsssbsss", "bsssbbsbsss", "bsssbbsssbs",
   "bbsbsssbsss", "bbsssbsbsss", "bbsssbsssbs", "bsbbsbbbsss",
   "bsbbsssbbbs", "bsssbbsbbbs", "bsbbbsbbsss", "bsbbbsssbbs",
   "bsssbbbsbbs", "bbbsbbbsbbs", "bbsbsssbbbs", "bbsssbsbbbs",
   "bbsbbbsbsss", "bbsbbbsssbs", "bbsbbbsbbbs", "bbbsbsbbsss",
   "bbbsbsssbbs", "bbbsssbsbbs", "bbbsbbsbsss", "bbbsbbsssbs",
   "bbbsssbbsbs", "bbbsbbbbsbs", "bbssbssssbs", "bbbbsssbsbs",
   "bsbssbbssss", "bsbssssbbss", "bssbsbbssss", "bssbssssbbs",
   "bssssbsbbss", "bssssbssbbs", "bsbbssbssss", "bsbbssssbss",
   "bssbbsbssss", "bssbbssssbs", "bssssbbsbss", "bssssbbssbs",
   "bbssssbssbs", "bbssbsbssss", "bbbbsbbbsbs", "bbssssbsbss",
   "bsssbbbbsbs", "bsbssbbbbss", "bssbsbbbbss", "bssbssbbbbs",
   "bsbbbbssbss", "bssbbbbsbss", "bssbbbbssbs", "bbbbsbssbss",
   "bbbbssbsbss", "bbbbssbssbs", "bbsbbsbbbbs", "bbsbbbbsbbs",
   "bbbbsbbsbbs", "bsbsbbbbsss", "bsbsssbbbbs", "bsssbsbbbbs",
   "bsbbbbsbsss", "bsbbbbsssbs", "bbbbsbsbsss", "bbbbsbsssbs",
   "bsbbbsbbbbs", "bsbbbbsbbbs", "bbbsbsbbbbs", "bbbbsbsbbbs",
   "bbsbssssbss", "bbsbssbssss", "bbsbssbbbss", "bbsssbbbsbsbb" };

 final int SETA = 0;
 final int SETB = 1;
 final int SETC = 2;

 byte ia_Buf[] = new byte[4096];
 int i_LenBuf;

 int i_Ratio;

 void BarcodeBase() {
  Clear();
  i_Ratio = 3;
 }

 void Clear() {

  int i;
  for (i = 0; i < 4096; i++)
   ia_Buf[i] = 0;
  i_LenBuf = 0;
 }

 int GetEncodeLength() {

  int i, iLen = 0;
  for (i = 0; i < i_LenBuf; i++) {
   if ((ia_Buf[i] & 2) != 0)
    iLen += (i_Ratio - 1);
  }
  return iLen + i_LenBuf;
 }

 int GetBufferLength() {
  return i_LenBuf;
 }

 int GetRatio() {
  return i_Ratio;
 }

 int SetRatio(int iRatio) {
  i_Ratio = iRatio;
  if (i_Ratio <= 0)
   i_Ratio = 1;
  return 0;
 }

 void DrawBarCodeLine(Graphics hDC, int sx, int sy, int ex, int ey,
   int Color, int penW) {
  // 이건 내가 그리는 구현하자
  // SetColorHEX(Color);
  // FillRect(g_ScreenFB,sx,sy,penW,ey);
  hDC.setColor(Color);
  hDC.drawLine(sx, sy, ex, ey);

  System.out.println("sx "+sx+" sy "+sy+" penW "+penW+" ey "+ey+" COLOR "+Color);
  // DEBUGMSG("sx %d sy %d ex %d ey %d COLOR %d\n",sx, sy, ex, ey,Color);

 }

 void DrawBarcode(Graphics hDC, int iX, int iY0, int iY10, int iY11,
   int iPenW) {
  int clrBar = 0x0;
  int clrSpace = 0xffffff;
  
  // byte *pb=ia_Buf;
  int i0, iNum0 = i_LenBuf;

  byte bBar;
  int i1, iNum1;
  int iY;
  System.out.println("i_LenBuf "+i_LenBuf);
  for (i0 = 0; i0 < iNum0; i0++) {
   bBar = (byte) (ia_Buf[i0] & 0x01);
   iNum1 = (ia_Buf[i0] & 0x02) != 0 ? i_Ratio : 1;
   iY = (ia_Buf[i0] & 0x04) != 0 ? iY11 : iY10;
   for (i1 = 0; i1 < iNum1; i1++) {
    
    if (bBar != 0) {
     DrawBarCodeLine(hDC, iX, iY0, iX, iY, clrBar, iPenW);
    } else {
     DrawBarCodeLine(hDC, iX, iY0, iX, iY, clrSpace, iPenW);
    }
    iX += iPenW;
   }

  }
 }

 boolean Encode128A(String pszCode) {
  Clear();
  char pszCodereturn[] = pszCode.toCharArray();
  // 혹시 널 붙지 않을까 걱정이네
  return P_Encode128(pszCodereturn, SETA);
 }

 void Draw128(Graphics hDC, int iX, int iY0, int iY1, int iPenW) {
  DrawBarcode(hDC, iX, iY0, iY1, iY1, iPenW);
 }

 boolean P_Encode128(char pszCode[], int iSetIn) {
  // Clear();
  // byte pFst[] = ia_Buf;
  // byte pb[] = ia_Buf;

  int iCheckDigit = GetCheckDigit(iSetIn, pszCode);

  int iNum = pszCode.length;

  int iChar, iCharNext;
  int iPosition = 0;
  int iSet = iSetIn;
  count = 0;

  if (iSetIn == SETA)
   ia_Buf = P_GetBarSpace128(ia_Buf, 103);
  else if (iSetIn == SETB)
   ia_Buf = P_GetBarSpace128(ia_Buf, 104);
  else
   ia_Buf = P_GetBarSpace128(ia_Buf, 105);

  if (ia_Buf == null)
   return false;

  while (iPosition < iNum) {
   {
    int iTemp2 = pszCode[iPosition];
    if (iTemp2 < -1)
     iTemp2 = iTemp2 & 255;

    iChar = ga2_Code128[iSet][iTemp2];

    ia_Buf = P_GetBarSpace128(ia_Buf, iChar);
    if (ia_Buf == null)
     return false;
    iPosition++;
    if (iSet == SETA) {
     if (iChar == 100)
      iSet = SETB;
     else if (iChar == 99)
      iSet = SETC;
    } else if (iSet == SETB) {
     if (iChar == 101)
      iSet = SETA;
     else if (iChar == 99)
      iSet = SETC;
    } else if (iChar == 98) {
     if (iSet == SETA)
      iCharNext = ga2_Code128[SETB][pszCode[iPosition]];
     else
      iCharNext = ga2_Code128[SETA][pszCode[iPosition]];

     ia_Buf = P_GetBarSpace128(ia_Buf, iChar);
     if (ia_Buf == null)
      return false;
     iPosition++;
    }
   }
  }

  ia_Buf = P_GetBarSpace128(ia_Buf, iCheckDigit);
  if (ia_Buf == null)
   return false;
  ia_Buf = P_GetBarSpace128(ia_Buf, 106);
  i_LenBuf = count;

  return true;
 }

 int count;

 byte[] P_GetBarSpace128(byte pb[], int iV) {
  int i;

  if (iV < 0)
   return null;
  if (iV > 106)
   return null;

  char buf[] = psz[iV].toCharArray();

  
  for (i = 0; i < 11; i++) {

   if (buf[i] == 'b')
    pb[count] += 1;
   count++;
  }
  if (iV == 106) {
   pb[count] += 1;
   count++;
   pb[count] += 1;
   count++;
  }
  return pb;
 }

 int GetCheckDigit(int iSet, char pszCode[]) {
  int iSum = 0, iCurSet = 0, iChar128, iCharNext, iWeight, iPosition;
  int iNum;

  iCurSet = iSet;
  if (iSet == SETA) {
   iSum = 103;
  } else if (iSet == SETB) {
   iSum = 104;
  } else if (iSet == SETC) {
   iSum = 105;
  }

  iPosition = 0;
  iWeight = 1;

  iNum = pszCode.length;
  while (iPosition < iNum) {

   {
    int iTemp2 = pszCode[iPosition];
    if (iTemp2 < -1)
     iTemp2 = iTemp2 & 255;

    iChar128 = ga2_Code128[iCurSet][iTemp2];

    iSum += (iWeight * iChar128);

    iPosition++;
    iWeight++;

    if (iCurSet == SETA) {
     if (iChar128 == 100)
      iCurSet = SETB;
     else if (iChar128 == 99)
      iCurSet = SETC;
    } else if (iCurSet == SETB) {
     if (iChar128 == 101)
      iCurSet = SETA;
     else if (iChar128 == 99)
      iCurSet = SETC;
    } else if (iChar128 == 98) {
     if (iCurSet == SETA)
      iCharNext = ga2_Code128[SETB][pszCode[iPosition]];
     else
      iCharNext = ga2_Code128[SETA][pszCode[iPosition]];

     iSum += (iWeight * iCharNext);
     iPosition++;
     iWeight++;
    }
   }
  }
  return iSum % 103;
 }
}

'알고리즘' 카테고리의 다른 글

gson 읽고 쓰기 java  (0) 2013.03.08
java des algorithm (자바 DES 알고리즘)  (0) 2011.07.25
swap  (0) 2011.04.27
도스명령어 년 월 일  (0) 2010.03.24
완성형 조합형을 이용한 한글 조합  (0) 2010.01.26
posted by 욱이다
2011. 4. 27. 09:53 알고리즘


아니 이렇게 좋은 swap을 봤나 !!
자료형에 관계없이 모든 것에 다 쓰이는 swap!!


#include <stdio.h>

void swap(void *a, void *b,int width)
{
 int t;

 int i;
 char *p = (char*)a;
 char *q = (char*)b;
 for(i=0; i<width; i++,p++,q++ )
 {
  t = *p;
  *p = *q;
  *q = t;
 }
}

int main()
{
 //int a=0x11111111, b=0x22222222;
 double a=3., b=4.;

 swap(&a,&b, sizeof(a));

 printf("a=%lf, b=%lf\n", a, b );
 //printf("a=%x, b=%x\n", a, b );
 return 0;
}

posted by 욱이다
2010. 3. 24. 15:23 알고리즘



년월일 분리해서 변수에다가 집어 넣기

for /F "tokens=1" %%a in ('date /t') do set orgdate=%%a

set yy=%orgdate:~0,4%
set mm=%orgdate:~5,2%
set dd=%orgdate:~8,2%


요건 시 분 분리

for /F "tokens=2" %%a in ('time /t') do set orgtime=%%a

set hh=%orgtime:~0,2%
set min=%orgtime:~3,2%

'알고리즘' 카테고리의 다른 글

barcode 128a 소스 (java,c 사용가능)  (0) 2011.07.13
swap  (0) 2011.04.27
완성형 조합형을 이용한 한글 조합  (0) 2010.01.26
삼각함수 테이블  (0) 2010.01.26
모바일 환경에서 루트값 구하기  (0) 2010.01.26
posted by 욱이다
2010. 1. 26. 09:50 알고리즘

복잡다 한글 조합 ...

내가 지금 해볼건 초성 자음 리스트가 쭉나와서 누르면 자동으로 중성 모음 리스트가 쭉 나온다 또 누르면 종성 자음 리스트가 쭉~!! 나온다 다누르면 한글 1자가 생성되는 것을 만들어 볼려고한다

초성 중성 종성
  없음
완성형 A4A1 A4A2 A4A4 A4BF A4C0 A4C1 0 A4A1 A4A2
조합형 2 3 4 3 4 5 1 2 3
 
완성형 A4A7 A4A8 A4A9 A4C2 A4C3 A4C4 A4A3 A4A4 A4A5
조합형 5 6 7 6 7 A 4 5 6
 
완성형 A4B1 A4B2 A4B3 A4C5 A4C6 A4C7 A4A6 A4A7 A4A9
조합형 8 9 A B C D 7 8 9
                 
 
완성형 A4B5 A4B6 A4B7 A4C8 A4C9 A4CA A4AA A4AB A4AC
조합형 B C D E F 12 A B C
 
완성형 A4B8 A4B9 A4BA A4CB A4CC A4CD A4AD A4AE A4AF
조합형 E F 10 13 14 15 D E F
 
완성형 A4BB A4BC A4BD A4CE A4CF A4D0 A4B0 A4B1 A4B2
조합형 11 12 13 16 17 1A 10 11 13
                 
     
완성형 A4BE     A4D1 A4D2 A4D3 A4B4 A4B5 A4B6
조합형 14     1B 1C 1D 14 15 16
             
완성형             A4B7 A4B8 A4BA
조합형             17 18 19
             
완성형 A4BB A4BC A4BD
조합형 1A 1B 1C
     
완성형 A4BE    
조합형 1D    

 

 
DrawString을 쓸때 보내는 데이타는 완성형 한글 조합 을 가지고 처리를 한다

그런데 지금 한글을 입력하는 키패드를 만들 것은

초성 자음 선택 -> 중성 모음 선택-> 종성 자음 선택 해서 그 조합한 글을 보이는 것인데

 

완성형데이타로 그려진 자판에서 하나를 선택하면 같은 위치에있는 조합형 데이타를 넣고 ->이걸 반복 해서 한글자를 만들면 그 조합형 데이타 초성 중성 종성을 unsigned short데이타로 만든다

이때 만드는 방법은

1비트, 초성 5비트, 중성 5비트, 종성 5비트  이다 (총 16비트 short값이된다)

만약 종성이 없는 것이라면 1비트 , 초성 5비트, 중성 5비트, +1 하면 "가"라는 종성이 없는 글이 나온다

앞에 나온 1비트는 한글인지 영어인지 나타내는 비트인데 한글일 경우에는 무조건 1을 채워 넣는다

 

완성형 조합형 변환 하는건 검색하면 천지 삐까리이다

 

쓰기 좋고 보기 좋은 한글이 컴퓨터 자판 뒤에서는 이렇게나 분답스럽게 작업을 하고있다는 것을 세삼 느낀다

영어라면 그저 꿀인데 ... 뭐 지들 있어봐야 a,b,c,d,거 뭐냐 .. 21자냐 ??

26자구만.. (객관적이고 믿음이 가는 정보를 제공하기위해 자판은 직접 세었습니다)

 


'알고리즘' 카테고리의 다른 글

barcode 128a 소스 (java,c 사용가능)  (0) 2011.07.13
swap  (0) 2011.04.27
도스명령어 년 월 일  (0) 2010.03.24
삼각함수 테이블  (0) 2010.01.26
모바일 환경에서 루트값 구하기  (0) 2010.01.26
posted by 욱이다
2010. 1. 26. 09:48 알고리즘

삼각함수표

자세히 보면

서로 값이 대칭이거나 -값으로 변했다 원이니깐

색깔로되어있는 부분은 모바일로 전환하기위해 소수점을 없애고 자연수로 만들어봤다

x sin x cos x tan x sinX cosX tanX
0 0 1 ** 0 1000  
1 0.0174524 0.99984769 0.01745506 17 1000 17
2 0.03489949 0.99939082 0.03492076 35 999 35
3 0.05233595 0.99862953 0.05240777 52 999 52
4 0.06975647 0.99756405 0.06992681 70 998 70
5 0.08715574 0.99619469 0.08748866 87 996 87
6 0.10452846 0.99452189 0.10510423 105 995 105
7 0.12186934 0.99254615 0.12278456 122 993 123
8 0.1391731 0.99026806 0.14054083 139 990 141
9 0.15643446 0.98768834 0.15838444 156 988 158
10 0.17364817 0.98480775 0.17632698 174 985 176
11 0.19080899 0.98162718 0.1943803 191 982 194
12 0.20791169 0.9781476 0.21255656 208 978 213
13 0.22495105 0.97437006 0.23086819 225 974 231
14 0.24192189 0.97029572 0.249328 242 970 249
15 0.25881904 0.96592582 0.26794919 259 966 268
16 0.27563735 0.96126169 0.28674538 276 961 287
17 0.2923717 0.95630475 0.30573068 292 956 306
18 0.30901699 0.95105651 0.32491969 309 951 325
19 0.32556815 0.94551857 0.34432761 326 946 344
20 0.34202014 0.93969262 0.36397023 342 940 364
21 0.35836794 0.93358042 0.38386403 358 934 384
22 0.37460659 0.92718385 0.40402622 375 927 404
23 0.39073112 0.92050485 0.42447481 391 921 424
24 0.40673664 0.91354545 0.44522868 407 914 445
25 0.42261826 0.90630778 0.46630765 423 906 466
26 0.43837114 0.89879404 0.48773258 438 899 488
27 0.45399049 0.89100652 0.50952544 454 891 510
28 0.46947156 0.88294759 0.53170943 469 883 532
29 0.48480962 0.8746197 0.55430905 485 875 554
30 0.49999999 0.8660254 0.57735026 500 866 577
31 0.51503807 0.8571673 0.60086061 515 857 601
32 0.52991926 0.84804809 0.62486935 530 848 625
33 0.54463903 0.83867056 0.64940759 545 839 649
34 0.5591929 0.82903757 0.67450851 559 829 675
35 0.57357643 0.81915204 0.70020753 574 819 700
36 0.58778525 0.80901699 0.72654252 588 809 727
37 0.60181502 0.79863551 0.75355405 602 799 754
38 0.61566147 0.78801075 0.78128562 616 788 781
39 0.62932039 0.77714596 0.80978403 629 777 810
40 0.6427876 0.76604444 0.83909963 643 766 839
41 0.65605902 0.75470958 0.86928673 656 755 869
42 0.6691306 0.74314482 0.90040404 669 743 900
43 0.68199836 0.7313537 0.93251508 682 731 933
44 0.69465837 0.7193398 0.96568877 695 719 966
45 0.70710678 0.70710678 0.99999999 707 707 1000
46 0.7193398 0.69465837 1.03553031 719 695 1036
47 0.7313537 0.68199836 1.0723687 731 682 1072
48 0.74314482 0.6691306 1.11061251 743 669 1111
49 0.75470958 0.65605902 1.1503684 755 656 1150
50 0.76604444 0.6427876 1.19175359 766 643 1192
51 0.77714596 0.62932039 1.23489715 777 629 1235
52 0.78801075 0.61566147 1.27994163 788 616 1280
53 0.79863551 0.60181502 1.32704482 799 602 1327
54 0.80901699 0.58778525 1.37638192 809 588 1376
55 0.81915204 0.57357643 1.428148 819 574 1428
56 0.82903757 0.5591929 1.48256096 829 559 1483
57 0.83867056 0.54463903 1.53986496 839 545 1540
58 0.84804809 0.52991926 1.60033452 848 530 1600
59 0.8571673 0.51503807 1.66427948 857 515 1664
60 0.8660254 0.5 1.7320508 866 500 1732
61 0.8746197 0.48480962 1.80404775 875 485 1804
62 0.88294759 0.46947156 1.88072646 883 469 1881
63 0.89100652 0.45399049 1.9626105 891 454 1963
64 0.89879404 0.43837114 2.05030384 899 438 2050
65 0.90630778 0.42261826 2.14450692 906 423 2145
66 0.91354545 0.40673664 2.24603677 914 407 2246
67 0.92050485 0.39073112 2.35585236 921 391 2356
68 0.92718385 0.37460659 2.47508685 927 375 2475
69 0.93358042 0.35836794 2.60508906 934 358 2605
70 0.93969262 0.34202014 2.74747741 940 342 2747
71 0.94551857 0.32556815 2.90421087 946 326 2904
72 0.95105651 0.30901699 3.07768353 951 309 3078
73 0.95630475 0.2923717 3.27085261 956 292 3271
74 0.96126169 0.27563735 3.48741444 961 276 3487
75 0.96592582 0.25881904 3.7320508 966 259 3732
76 0.97029572 0.24192189 4.01078093 970 242 4011
77 0.97437006 0.22495105 4.33147587 974 225 4331
78 0.9781476 0.20791169 4.7046301 978 208 4705
79 0.98162718 0.19080899 5.14455401 982 191 5145
80 0.98480775 0.17364817 5.67128181 985 174 5671
81 0.98768834 0.15643446 6.31375151 988 156 6314
82 0.99026806 0.1391731 7.11536972 990 139 7115
83 0.99254615 0.12186934 8.14434642 993 122 8144
84 0.99452189 0.10452846 9.51436445 995 105 9514
85 0.99619469 0.08715574 11.43005229 996 87 11430
86 0.99756405 0.06975647 14.30066624 998 70 14301
87 0.99862953 0.05233595 19.08113667 999 52 19081
88 0.99939082 0.03489949 28.63625324 999 35 28636
89 0.99984769 0.0174524 57.28996148 1000 17 57290
90 1 0 ** 1000 0 #VALUE!
91 0.99984769 -0.0174524 -57.28996177 1000 -17 -57290
92 0.99939082 -0.03489949 -28.63625332 999 -35 -28636
93 0.99862953 -0.05233595 -19.0811367 999 -52 -19081
94 0.99756405 -0.06975647 -14.30066626 998 -70 -14301
95 0.99619469 -0.08715574 -11.4300523 996 -87 -11430
96 0.99452189 -0.10452846 -9.51436445 995 -105 -9514
97 0.99254615 -0.12186934 -8.14434643 993 -122 -8144
98 0.99026806 -0.1391731 -7.11536972 990 -139 -7115
99 0.98768834 -0.15643446 -6.31375151 988 -156 -6314
100 0.98480775 -0.17364817 -5.67128182 985 -174 -5671
101 0.98162718 -0.19080899 -5.14455401 982 -191 -5145
102 0.9781476 -0.20791169 -4.70463011 978 -208 -4705
103 0.97437006 -0.22495105 -4.33147587 974 -225 -4331
104 0.97029572 -0.24192189 -4.01078093 970 -242 -4011
105 0.96592582 -0.25881904 -3.7320508 966 -259 -3732
106 0.96126169 -0.27563735 -3.48741444 961 -276 -3487
107 0.95630475 -0.2923717 -3.27085261 956 -292 -3271
108 0.95105651 -0.30901699 -3.07768353 951 -309 -3078
109 0.94551857 -0.32556815 -2.90421087 946 -326 -2904
110 0.93969262 -0.34202014 -2.74747741 940 -342 -2747
111 0.93358042 -0.35836794 -2.60508906 934 -358 -2605
112 0.92718385 -0.37460659 -2.47508685 927 -375 -2475
113 0.92050485 -0.39073112 -2.35585236 921 -391 -2356
114 0.91354545 -0.40673664 -2.24603677 914 -407 -2246
115 0.90630778 -0.42261826 -2.14450692 906 -423 -2145
116 0.89879404 -0.43837114 -2.05030384 899 -438 -2050
117 0.89100652 -0.45399049 -1.9626105 891 -454 -1963
118 0.88294759 -0.46947156 -1.88072646 883 -469 -1881
119 0.8746197 -0.48480962 -1.80404775 875 -485 -1804
120 0.8660254 -0.49999999 -1.7320508 866 -500 -1732
121 0.8571673 -0.51503807 -1.66427948 857 -515 -1664
122 0.84804809 -0.52991926 -1.60033452 848 -530 -1600
123 0.83867056 -0.54463903 -1.53986496 839 -545 -1540
124 0.82903757 -0.5591929 -1.48256096 829 -559 -1483
125 0.81915204 -0.57357643 -1.428148 819 -574 -1428
126 0.80901699 -0.58778525 -1.37638192 809 -588 -1376
127 0.79863551 -0.60181502 -1.32704482 799 -602 -1327
128 0.78801075 -0.61566147 -1.27994163 788 -616 -1280
129 0.77714596 -0.62932039 -1.23489715 777 -629 -1235
130 0.76604444 -0.6427876 -1.19175359 766 -643 -1192
131 0.75470958 -0.65605902 -1.1503684 755 -656 -1150
132 0.74314482 -0.6691306 -1.11061251 743 -669 -1111
133 0.7313537 -0.68199836 -1.07236871 731 -682 -1072
134 0.7193398 -0.69465837 -1.03553031 719 -695 -1036
135 0.70710678 -0.70710678 -1 707 -707 -1000
136 0.69465837 -0.7193398 -0.96568877 695 -719 -966
137 0.68199836 -0.7313537 -0.93251508 682 -731 -933
138 0.6691306 -0.74314482 -0.90040404 669 -743 -900
139 0.65605902 -0.75470958 -0.86928673 656 -755 -869
140 0.6427876 -0.76604444 -0.83909963 643 -766 -839
141 0.62932039 -0.77714596 -0.80978403 629 -777 -810
142 0.61566147 -0.78801075 -0.78128562 616 -788 -781
143 0.60181502 -0.79863551 -0.75355405 602 -799 -754
144 0.58778525 -0.80901699 -0.72654252 588 -809 -727
145 0.57357643 -0.81915204 -0.70020753 574 -819 -700
146 0.5591929 -0.82903757 -0.67450851 559 -829 -675
147 0.54463903 -0.83867056 -0.64940759 545 -839 -649
148 0.52991926 -0.84804809 -0.62486935 530 -848 -625
149 0.51503807 -0.8571673 -0.60086061 515 -857 -601
150 0.5 -0.8660254 -0.57735026 500 -866 -577
151 0.48480962 -0.8746197 -0.55430905 485 -875 -554
152 0.46947156 -0.88294759 -0.53170943 469 -883 -532
153 0.45399049 -0.89100652 -0.50952544 454 -891 -510
154 0.43837114 -0.89879404 -0.48773258 438 -899 -488
155 0.42261826 -0.90630778 -0.46630765 423 -906 -466
156 0.40673664 -0.91354545 -0.44522868 407 -914 -445
157 0.39073112 -0.92050485 -0.42447481 391 -921 -424
158 0.37460659 -0.92718385 -0.40402622 375 -927 -404
159 0.35836794 -0.93358042 -0.38386403 358 -934 -384
160 0.34202014 -0.93969262 -0.36397023 342 -940 -364
161 0.32556815 -0.94551857 -0.34432761 326 -946 -344
162 0.30901699 -0.95105651 -0.32491969 309 -951 -325
163 0.2923717 -0.95630475 -0.30573068 292 -956 -306
164 0.27563735 -0.96126169 -0.28674538 276 -961 -287
165 0.25881904 -0.96592582 -0.26794919 259 -966 -268
166 0.24192189 -0.97029572 -0.249328 242 -970 -249
167 0.22495105 -0.97437006 -0.23086819 225 -974 -231
168 0.20791169 -0.9781476 -0.21255656 208 -978 -213
169 0.19080899 -0.98162718 -0.1943803 191 -982 -194
170 0.17364817 -0.98480775 -0.17632698 174 -985 -176
171 0.15643446 -0.98768834 -0.15838444 156 -988 -158
172 0.1391731 -0.99026806 -0.14054083 139 -990 -141
173 0.12186934 -0.99254615 -0.12278456 122 -993 -123
174 0.10452846 -0.99452189 -0.10510423 105 -995 -105
175 0.08715574 -0.99619469 -0.08748866 87 -996 -87
176 0.06975647 -0.99756405 -0.06992681 70 -998 -70
177 0.05233595 -0.99862953 -0.05240777 52 -999 -52
178 0.03489949 -0.99939082 -0.03492076 35 -999 -35
179 0.0174524 -0.99984769 -0.01745506 17 -1000 -17
180 0 -1 ** 0 -1000 #VALUE!
181 -0.0174524 -0.99984769 0.01745506 -17 -1000 17
182 -0.03489949 -0.99939082 0.03492076 -35 -999 35
183 -0.05233595 -0.99862953 0.05240777 -52 -999 52
184 -0.06975647 -0.99756405 0.06992681 -70 -998 70
185 -0.08715574 -0.99619469 0.08748866 -87 -996 87
186 -0.10452846 -0.99452189 0.10510423 -105 -995 105
187 -0.12186934 -0.99254615 0.12278456 -122 -993 123
188 -0.1391731 -0.99026806 0.14054083 -139 -990 141
189 -0.15643446 -0.98768834 0.15838444 -156 -988 158
190 -0.17364817 -0.98480775 0.17632698 -174 -985 176
191 -0.19080899 -0.98162718 0.1943803 -191 -982 194
192 -0.20791169 -0.9781476 0.21255656 -208 -978 213
193 -0.22495105 -0.97437006 0.23086819 -225 -974 231
194 -0.24192189 -0.97029572 0.249328 -242 -970 249
195 -0.25881904 -0.96592582 0.26794919 -259 -966 268
196 -0.27563735 -0.96126169 0.28674538 -276 -961 287
197 -0.2923717 -0.95630475 0.30573068 -292 -956 306
198 -0.30901699 -0.95105651 0.32491969 -309 -951 325
199 -0.32556815 -0.94551857 0.34432761 -326 -946 344
200 -0.34202014 -0.93969262 0.36397023 -342 -940 364
201 -0.35836794 -0.93358042 0.38386403 -358 -934 384
202 -0.37460659 -0.92718385 0.40402622 -375 -927 404
203 -0.39073112 -0.92050485 0.42447481 -391 -921 424
204 -0.40673664 -0.91354545 0.44522868 -407 -914 445
205 -0.42261826 -0.90630778 0.46630765 -423 -906 466
206 -0.43837114 -0.89879404 0.48773258 -438 -899 488
207 -0.45399049 -0.89100652 0.50952544 -454 -891 510
208 -0.46947156 -0.88294759 0.53170943 -469 -883 532
209 -0.48480962 -0.8746197 0.55430905 -485 -875 554
210 -0.49999999 -0.8660254 0.57735026 -500 -866 577
211 -0.51503807 -0.8571673 0.60086061 -515 -857 601
212 -0.52991926 -0.84804809 0.62486935 -530 -848 625
213 -0.54463903 -0.83867056 0.64940759 -545 -839 649
214 -0.5591929 -0.82903757 0.67450851 -559 -829 675
215 -0.57357643 -0.81915204 0.70020753 -574 -819 700
216 -0.58778525 -0.80901699 0.72654252 -588 -809 727
217 -0.60181502 -0.79863551 0.75355404 -602 -799 754
218 -0.61566147 -0.78801075 0.78128562 -616 -788 781
219 -0.62932039 -0.77714596 0.80978403 -629 -777 810
220 -0.6427876 -0.76604444 0.83909963 -643 -766 839
221 -0.65605902 -0.75470958 0.86928673 -656 -755 869
222 -0.6691306 -0.74314482 0.90040404 -669 -743 900
223 -0.68199835 -0.7313537 0.93251508 -682 -731 933
224 -0.69465837 -0.7193398 0.96568877 -695 -719 966
225 -0.70710678 -0.70710678 0.99999999 -707 -707 1000
226 -0.7193398 -0.69465837 1.03553031 -719 -695 1036
227 -0.7313537 -0.68199836 1.0723687 -731 -682 1072
228 -0.74314482 -0.6691306 1.11061251 -743 -669 1111
229 -0.75470958 -0.65605902 1.1503684 -755 -656 1150
230 -0.76604444 -0.6427876 1.19175359 -766 -643 1192
231 -0.77714596 -0.62932039 1.23489715 -777 -629 1235
232 -0.78801075 -0.61566147 1.27994163 -788 -616 1280
233 -0.7986355 -0.60181502 1.32704482 -799 -602 1327
234 -0.80901699 -0.58778525 1.37638192 -809 -588 1376
235 -0.81915204 -0.57357643 1.428148 -819 -574 1428
236 -0.82903757 -0.5591929 1.48256096 -829 -559 1483
237 -0.83867056 -0.54463903 1.53986496 -839 -545 1540
238 -0.84804809 -0.52991926 1.60033452 -848 -530 1600
239 -0.8571673 -0.51503807 1.66427948 -857 -515 1664
240 -0.8660254 -0.5 1.7320508 -866 -500 1732
241 -0.8746197 -0.48480962 1.80404775 -875 -485 1804
242 -0.88294759 -0.46947156 1.88072646 -883 -469 1881
243 -0.89100652 -0.45399049 1.9626105 -891 -454 1963
244 -0.89879404 -0.43837114 2.05030384 -899 -438 2050
245 -0.90630778 -0.42261826 2.14450691 -906 -423 2145
246 -0.91354545 -0.40673664 2.24603677 -914 -407 2246
247 -0.92050485 -0.39073112 2.35585236 -921 -391 2356
248 -0.92718385 -0.37460659 2.47508685 -927 -375 2475
249 -0.93358042 -0.35836794 2.60508906 -934 -358 2605
250 -0.93969262 -0.34202014 2.74747741 -940 -342 2747
251 -0.94551857 -0.32556815 2.90421087 -946 -326 2904
252 -0.95105651 -0.30901699 3.07768353 -951 -309 3078
253 -0.95630475 -0.2923717 3.27085261 -956 -292 3271
254 -0.96126169 -0.27563735 3.48741444 -961 -276 3487
255 -0.96592582 -0.25881904 3.7320508 -966 -259 3732
256 -0.97029572 -0.24192189 4.01078093 -970 -242 4011
257 -0.97437006 -0.22495105 4.33147587 -974 -225 4331
258 -0.9781476 -0.20791169 4.7046301 -978 -208 4705
259 -0.98162718 -0.19080899 5.14455401 -982 -191 5145
260 -0.98480775 -0.17364817 5.67128181 -985 -174 5671
261 -0.98768834 -0.15643446 6.3137515 -988 -156 6314
262 -0.99026806 -0.1391731 7.11536971 -990 -139 7115
263 -0.99254615 -0.12186934 8.14434641 -993 -122 8144
264 -0.99452189 -0.10452846 9.51436444 -995 -105 9514
265 -0.99619469 -0.08715574 11.43005228 -996 -87 11430
266 -0.99756405 -0.06975647 14.30066622 -998 -70 14301
267 -0.99862953 -0.05233595 19.08113663 -999 -52 19081
268 -0.99939082 -0.03489949 28.63625317 -999 -35 28636
269 -0.99984769 -0.0174524 57.28996119 -1000 -17 57290
270 -1 0 ** -1000 0 #VALUE!
271 -0.99984769 0.0174524 -57.28996207 -1000 17 -57290
272 -0.99939082 0.03489949 -28.63625339 -999 35 -28636
273 -0.99862953 0.05233595 -19.08113673 -999 52 -19081
274 -0.99756405 0.06975647 -14.30066628 -998 70 -14301
275 -0.99619469 0.08715574 -11.43005232 -996 87 -11430
276 -0.99452189 0.10452846 -9.51436446 -995 105 -9514
277 -0.99254615 0.12186934 -8.14434643 -993 122 -8144
278 -0.99026806 0.1391731 -7.11536972 -990 139 -7115
279 -0.98768834 0.15643446 -6.31375152 -988 156 -6314
280 -0.98480775 0.17364817 -5.67128182 -985 174 -5671
281 -0.98162718 0.19080899 -5.14455401 -982 191 -5145
282 -0.9781476 0.20791169 -4.70463011 -978 208 -4705
283 -0.97437006 0.22495105 -4.33147587 -974 225 -4331
284 -0.97029572 0.24192189 -4.01078093 -970 242 -4011
285 -0.96592582 0.25881904 -3.7320508 -966 259 -3732
286 -0.96126169 0.27563735 -3.48741444 -961 276 -3487
287 -0.95630475 0.2923717 -3.27085262 -956 292 -3271
288 -0.95105651 0.30901699 -3.07768353 -951 309 -3078
289 -0.94551857 0.32556815 -2.90421087 -946 326 -2904
290 -0.93969262 0.34202014 -2.74747742 -940 342 -2747
291 -0.93358042 0.35836794 -2.60508906 -934 358 -2605
292 -0.92718385 0.37460659 -2.47508685 -927 375 -2475
293 -0.92050485 0.39073112 -2.35585236 -921 391 -2356
294 -0.91354545 0.40673664 -2.24603677 -914 407 -2246
295 -0.90630778 0.42261826 -2.14450692 -906 423 -2145
296 -0.89879404 0.43837114 -2.05030384 -899 438 -2050
297 -0.89100652 0.45399049 -1.9626105 -891 454 -1963
298 -0.88294759 0.46947156 -1.88072646 -883 469 -1881
299 -0.8746197 0.48480962 -1.80404775 -875 485 -1804
300 -0.8660254 0.49999999 -1.7320508 -866 500 -1732
301 -0.8571673 0.51503807 -1.66427948 -857 515 -1664
302 -0.84804809 0.52991926 -1.60033452 -848 530 -1600
303 -0.83867056 0.54463903 -1.53986496 -839 545 -1540
304 -0.82903757 0.5591929 -1.48256096 -829 559 -1483
305 -0.81915204 0.57357643 -1.428148 -819 574 -1428
306 -0.80901699 0.58778525 -1.37638192 -809 588 -1376
307 -0.79863551 0.60181502 -1.32704482 -799 602 -1327
308 -0.78801075 0.61566147 -1.27994163 -788 616 -1280
309 -0.77714596 0.62932039 -1.23489715 -777 629 -1235
310 -0.76604444 0.6427876 -1.19175359 -766 643 -1192
311 -0.75470958 0.65605902 -1.1503684 -755 656 -1150
312 -0.74314482 0.6691306 -1.11061251 -743 669 -1111
313 -0.7313537 0.68199835 -1.07236871 -731 682 -1072
314 -0.7193398 0.69465837 -1.03553031 -719 695 -1036
315 -0.70710678 0.70710678 -1 -707 707 -1000
316 -0.69465837 0.7193398 -0.96568877 -695 719 -966
317 -0.68199836 0.7313537 -0.93251508 -682 731 -933
318 -0.6691306 0.74314482 -0.90040404 -669 743 -900
319 -0.65605902 0.75470958 -0.86928673 -656 755 -869
320 -0.6427876 0.76604444 -0.83909963 -643 766 -839
321 -0.62932039 0.77714596 -0.80978403 -629 777 -810
322 -0.61566147 0.78801075 -0.78128562 -616 788 -781
323 -0.60181502 0.7986355 -0.75355405 -602 799 -754
324 -0.58778525 0.80901699 -0.72654252 -588 809 -727
325 -0.57357643 0.81915204 -0.70020753 -574 819 -700
326 -0.5591929 0.82903757 -0.67450851 -559 829 -675
327 -0.54463903 0.83867056 -0.64940759 -545 839 -649
328 -0.52991926 0.84804809 -0.62486935 -530 848 -625
329 -0.51503807 0.8571673 -0.60086061 -515 857 -601
330 -0.5 0.8660254 -0.57735026 -500 866 -577
331 -0.48480962 0.8746197 -0.55430905 -485 875 -554
332 -0.46947156 0.88294759 -0.53170943 -469 883 -532
333 -0.45399049 0.89100652 -0.50952544 -454 891 -510
334 -0.43837114 0.89879404 -0.48773258 -438 899 -488
335 -0.42261826 0.90630778 -0.46630765 -423 906 -466
336 -0.40673664 0.91354545 -0.44522868 -407 914 -445
337 -0.39073112 0.92050485 -0.42447481 -391 921 -424
338 -0.37460659 0.92718385 -0.40402622 -375 927 -404
339 -0.35836794 0.93358042 -0.38386403 -358 934 -384
340 -0.34202014 0.93969262 -0.36397023 -342 940 -364
341 -0.32556815 0.94551857 -0.34432761 -326 946 -344
342 -0.30901699 0.95105651 -0.32491969 -309 951 -325
343 -0.2923717 0.95630475 -0.30573068 -292 956 -306
344 -0.27563735 0.96126169 -0.28674538 -276 961 -287
345 -0.25881904 0.96592582 -0.26794919 -259 966 -268
346 -0.24192189 0.97029572 -0.249328 -242 970 -249
347 -0.22495105 0.97437006 -0.23086819 -225 974 -231
348 -0.20791169 0.9781476 -0.21255656 -208 978 -213
349 -0.19080899 0.98162718 -0.1943803 -191 982 -194
350 -0.17364817 0.98480775 -0.17632698 -174 985 -176
351 -0.15643446 0.98768834 -0.15838444 -156 988 -158
352 -0.1391731 0.99026806 -0.14054083 -139 990 -141
353 -0.12186934 0.99254615 -0.12278456 -122 993 -123
354 -0.10452846 0.99452189 -0.10510423 -105 995 -105
355 -0.08715574 0.99619469 -0.08748866 -87 996 -87
356 -0.06975647 0.99756405 -0.06992681 -70 998 -70
357 -0.05233595 0.99862953 -0.05240777 -52 999 -52
358 -0.03489949 0.99939082 -0.03492076 -35 999 -35
359 -0.0174524 0.99984769 -0.01745506 -17 1000 -17
360 0 1 ** 0 1000 #VALUE!

 

위의 표를 이용해서 반지름과 각도를 알때 원의 원하는 각도와 반지름에 해당하는 지점을 알 수있다

for( i = 0 ; i <85; i +=10)
{
   x    = 원점x + (getCircleX(i,반지름)/1000);
   y    = 원점y+ (getCircleY(i,반지름)/1000);
   FillRect(x,y,10,10);
}

short Sin[90]={17,35,52,70,87,105,122,139,156,174,191,208,225,242,259,
    276,292,309,326,342,358,375,391,407,423,438,454,469,485,500,
    515,530,545,559,574,588,602,616,629,643,656,669,682,695,707,
    719,731,743,755,766,777,788,799,809,819,829,839,848,857,866,
    875,883,891,899,906,914,921,927,934,940,946,951,956,961,966,
    970,974,978,982,985,988,990,993,995,996,998,999,999,1000};


int getCircleY(int radian, int r){
 Byte State=0;
 Byte index;
 if(radian == 0 || radian == 180 || radian == 360)
  return 0;
 else if (radian == 90)
  return -r*1000;
 else if (radian == 270)
  return r*1000;

 State = radian/90;
 switch(State)
 {
 case 0:
  index = ((radian%90)) -1;
  return -(Sin[index] * r); 
 case 1:
  index = abs((radian%90) -1 -89);
  return -(Sin[index] * r);
 case 2:
  index = (radian%90) -1;
  return (Sin[index] * r); 
 case 3:

  index = abs((radian%90) -1 -89);
  return (Sin[index] * r);
 }
 return 0 ;
}
int getCircleX(int radian , int r)
{
 Byte State;
 if(radian == 0 )
  return r*1000;
 State = radian / 90;
 switch(State)
 {
 case 0:
  return -getCircleY(radian + 90,r);  
 case 1:
  return getCircleY(radian - 90,r);
 case 2:
  return -getCircleY(radian + 90,r);
 case 3:
  return getCircleY(radian - 90,r);
 }
 return 0;
}

 

 

'알고리즘' 카테고리의 다른 글

barcode 128a 소스 (java,c 사용가능)  (0) 2011.07.13
swap  (0) 2011.04.27
도스명령어 년 월 일  (0) 2010.03.24
완성형 조합형을 이용한 한글 조합  (0) 2010.01.26
모바일 환경에서 루트값 구하기  (0) 2010.01.26
posted by 욱이다
2010. 1. 26. 09:46 알고리즘

루트 값을 알면 포물선운동도 가능 할꺼 같아서 찾아봤다

보통의 c에서는 float연산이 되지만 모바일에서는 float연산이 되지 않아

my_sqrt(int x)에서 x*=10000의 연산을 통해서 소수점 두째 자리 까지 찍게 하였다

그래서 만약에 my_sqrt(2)의 값은 1.414... 이렇게 나오지만 여기에서는 141로 나온다

---------------------------------------------------------------------------

MC_knlSprintk(str,"215=> %d\n",my_sqrt(215));
MC_grpDrawString(ScreenFB , 10, 10, str,strlen(str), &g_GC);

---------------------------------------------------------------------------

int my_sqrt(int x)
{
 //루트의 근을 구하는 공식
 //4를 넣으면 200이 나온다 이것은 2.00이다
 //x *=10000;이 연산으로 인해 뒤에 두자리가 나왓다
 int guess_y = 1;
 int quotient;
 int average;
 int error = 10;
 
 if(x < 0)
  return x;

 x *=10000;
 while(error > 1)
 {
  quotient = x/guess_y;
  average = (guess_y + quotient) / 2;
  error = abs(average - guess_y);
  guess_y = average; 
 }

 return guess_y;
}


'알고리즘' 카테고리의 다른 글

barcode 128a 소스 (java,c 사용가능)  (0) 2011.07.13
swap  (0) 2011.04.27
도스명령어 년 월 일  (0) 2010.03.24
완성형 조합형을 이용한 한글 조합  (0) 2010.01.26
삼각함수 테이블  (0) 2010.01.26
posted by 욱이다
prev 1 next