Last active
February 25, 2016 16:21
-
-
Save FrankWu100/5bd998de4243959e2dca to your computer and use it in GitHub Desktop.
將角度(0~360)換算為東西南北表示
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| public string convertWindDirection(double directionAngle, int precision) | |
| { | |
| if (precision != 4 && precision != 8 && precision != 16 && precision != 32) | |
| return "\"precision\"準確度設定錯誤, 須為 4 or 8 or 16 or 32."; | |
| string[] windDirectionName = new string[32] { "北", "北微東", "北北東", "東北微北", "東北", "東北微東", "東北東", "東微北", | |
| "東", "東微南", "東南東", "東南微東", "東南", "東南微南", "南南東", "南微東", | |
| "南", "南微西", "南南西", "西南微南", "西南", "西南微西", "西南西", "西微南", | |
| "西", "西微北", "西北西", "西北微西", "西北", "西北微北", "北北西", "北微西" }; | |
| directionAngle = (directionAngle < 0) ? directionAngle + 360 : directionAngle; | |
| double angleRange = 360 / Convert.ToDouble(precision); | |
| int correct = 32 / precision; | |
| int angleSelect = Convert.ToInt32(Math.Floor((directionAngle + angleRange / 2) % 360 / angleRange)); | |
| return windDirectionName[angleSelect * correct]; | |
| } | |
| /* | |
| 將方向角度轉換為東南西北方位 | |
| 函式為 getWindDirection(double directionAngle, int precision) | |
| directionAngle 為傳入的角度 | |
| precision 為準確度 (4, 8, 16, 32) | |
| 精準度4方向有: | |
| 北, 東, 南, 西 | |
| 精準度8方向加: | |
| 東北, 東南, 西南, 西北 | |
| 精準度16方向加: | |
| 北北東, 東北東, 東南東, 南南東 | |
| 南南西, 西南西, 西北西, 北北西 | |
| 精準度32方向加: | |
| 北微東, 東北微北, 東北微東, 東微北 | |
| 東微南, 東南微東, 東南微南, 南微東 | |
| 南微西, 西南微南, 西南微西, 西微南 | |
| 西微北, 西北微西, 西北微北, 北微西 | |
| */ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment