로그인

이메일
비밀번호

Category (298)
MySpace (86)
Astronomy (46)
Development (144)
Drum (22)
«   2008년 08월   »
          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            
천문노트(Astronote.org)
Flex 별자리판
Flex Cublic Spline 보간법 프로그램
Flex/AIR Docs 한글화 페이지
 

지돌스타의 Flex와 천문프로그래밍

Flex, AIR, ActionScript, Ajax등 개발관련 자료 및 천문프로그래밍을 위한 공간입니다. 지돌스타
 A키 : 이전글, S키 : 다음글


구에서 두 지점간의 거리에 대한 글을 예전에 쓴 적이 있다. 이것을 Flex로 구현해보았다.

참고글 : http://blog.jidolstar.com/172 

아래의 위 프로그램의 소스코드이다.

main.mxml (Language : xml)
<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute">

    <mx:Script>
        <![CDATA[
            import mx.controls.Alert;
            private function calculate(radius:Number, lon1:Number, lat1:Number, lon2:Number, lat2:Number):Number
            {
                if(radius <= 0)
                {
                    mx.controls.Alert.show("반지름은 0보다 커야합니다.");
                    return 0;
                }            
                if(lon1 < 0 || lon1>360)
                {
                    mx.controls.Alert.show("경도는 0~360사이값이어야 합니다.");
                    return 0;
                }
                if(lon2 < 0 || lon2>360)
                {
                    mx.controls.Alert.show("경도는 0~360사이값이어야 합니다.");
                    return 0;
                }
                if(lat1 < -90 || lat1>90)
                {
                    mx.controls.Alert.show("위도는 -90~90사이값이어야 합니다.");
                    return 0;
                }
                if(lat1 < -90 || lat1>90)
                {
                    mx.controls.Alert.show("위도는 -90~90사이값이어야 합니다.");
                    return 0;
                }
                var D2R:Number = Math.PI / 180.0;
                lon1 = lon1 * D2R;
                lat1 = lat1 * D2R;
                lon2 = lon2 * D2R;
                lat2 = lat2 * D2R;
                var dlon:Number = lon2-lon1;
                var dlat:Number = lat2-lat1;
                var a:Number = Math.pow( Math.sin(dlat/2.0), 2.0) + Math.cos(lat1) * Math.cos(lat2) * Math.pow(Math.sin(dlon/2.0),2.0);
                var c:Number = 2.0 * Math.atan2( Math.sqrt(a), Math.sqrt(1-a));
                var distance:Number = radius* c;
                return distance;
            }
        ]]>

    </mx:Script>
    <mx:Panel layout="vertical" title="구에서 두 지점간의 거리 구하기" height="550" y="0" width="550" x="0"
        paddingBottom="5" paddingLeft="5" paddingRight="5" paddingTop="5">


        <mx:TabNavigator width="100%" height="100%" paddingBottom="5" paddingLeft="5" paddingRight="5" paddingTop="5">
            <mx:Canvas label="계산" width="100%" height="100%">
                <mx:VBox>
                    <mx:Label text="입력값"/>
                    <mx:HBox>
                        <mx:Form x="10" y="10" width="100%" height="100%">
                            <mx:FormHeading label="1 지점"/>
                            <mx:FormItem label="경도">
                                <mx:TextInput id="txtLon1" x="66" y="100" restrict="[0-9\.]"  text="0"/>
                            </mx:FormItem>
                            <mx:FormItem label="위도">
                                <mx:TextInput id="txtLat1" x="66" y="100" restrict="[\-0-9\.]" text="90"/>
                            </mx:FormItem>
                        </mx:Form>
                        <mx:Form x="10" y="10" width="100%" height="100%">
                            <mx:FormHeading label="2 지점"/>
                            <mx:FormItem label="경도">
                                <mx:TextInput id="txtLon2" x="66" y="100" restrict="[0-9\.]" text="0"/>
                            </mx:FormItem>
                            <mx:FormItem label="위도">
                                <mx:TextInput id="txtLat2" x="66" y="100" restrict="[\-0-9\.]" text="-90"/>
                            </mx:FormItem>
                        </mx:Form>
                    </mx:HBox>
                    <mx:Form x="10" y="10" width="100%" height="100%">
                        <mx:FormItem label="구의 반지름(지구반지름 km)">
                            <mx:TextInput id="txtRadius" x="66" y="100" restrict="[0-9]"  maxChars="3" text="6376.5" width="114"/>
                        </mx:FormItem>
                    </mx:Form>
                    <mx:Box horizontalAlign="right" width="100%">
                        <mx:Button x="181" y="170" label="거리계산" click="txtResult.text = String(calculate(Number(txtRadius.text), Number(txtLon1.text), Number(txtLat1.text), Number(txtLon2.text), Number(txtLat2.text)))"/>
                    </mx:Box>   
                   
                    <mx:HRule width="100%"/>
                    <mx:Label text="계산결과"/>
                    <mx:TextInput id="txtResult" width="100%"/>     
                </mx:VBox>     
            </mx:Canvas>
            <mx:Canvas label="공식" width="100%" height="100%">
                <mx:VBox>
                    <mx:Image source="@Embed('1348441504.png')" />
                    <mx:Image source="@Embed('1282734412.png')"/>
                </mx:VBox>     
            </mx:Canvas>

        </mx:TabNavigator>
        <mx:ApplicationControlBar width="100%">
            <mx:HBox id="footerBox" width="100%" height="26" y="{this.height-footerBox.height}">
                <mx:LinkButton label="Adobe Flex/AIR Korean documentation"
                    click="navigateToURL(new URLRequest('http://flexdocs.kr'));"
                    styleName="footerLink" textDecoration="underline" alpha="0.2"
                    />

                <mx:Spacer width="100%" />
                <mx:LinkButton label="Created by Jidolstar"
                    click="navigateToURL(new URLRequest('http://blog.jidolstar.com/'));"
                    styleName="footerLink"
                    textDecoration="underline" alpha="0.2"
                    />

            </mx:HBox> 
        </mx:ApplicationControlBar>
    </mx:Panel>

    <mx:Style>
        Application{
            fontSize:12pt
        }
        .flexdocLink{
            fontFamily: Verdana;
            fontSize: 12;
            fontWeight: normal;
            color: #FFFFFF;   
            rollOverColor: #FFFFFF;
            textRollOverColor: #FFFFFF;
            selectionColor: #FFFFFF;
            textSelectionColor: #000000;
        }
       
        .footerLink {
            fontFamily: Verdana;
            fontSize: 9;
            fontWeight: normal;
            color: #FFFFFF;   
            rollOverColor: #FFFFFF;
            textRollOverColor: #FFFFFF;
            selectionColor: #FFFFFF;
            textSelectionColor: #000000;
    }      
       
    </mx:Style> 
</mx:Application>
 


글쓴이 : 지돌스타(http://blog.jidolstar.com/217 )

이올린에 북마크하기(0) 이올린에 추천하기(0)
이 글의 관련글
오늘의 인기글
전체조회 1465 : 오늘조회 3

트랙백 주소 :: http://blog.jidolstar.com/trackback/217

댓글을 달아 주세요