Last active
January 8, 2021 08:40
-
-
Save kimsama/10437486 to your computer and use it in GitHub Desktop.
근사값을 구하는 함수 예, 주어진 배열에서 p와 가장 근사한 배열값의 인덱스를 리턴. A function which returns the array index of most approximate value with the p.
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
| /// <summary> | |
| /// 주어진 배열에서 p와 가장 근사한 배열값의 인덱스를 리턴. | |
| /// </summary> | |
| public static int Near(float[] array, float p) | |
| { | |
| float tmp = 0f; | |
| float min = 100f; | |
| float near = 0f; | |
| int found = 0; | |
| for(int i=0; i<array.Length; i++) | |
| { | |
| tmp = array[i] - p; | |
| if (Math.Abs(min) > Math.Abs(tmp)) | |
| { | |
| min = tmp; | |
| near = array[i]; | |
| found = i; | |
| } | |
| } | |
| //Debug.Log ("Near: " + near.ToString ()); | |
| return found; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
땡큐베리망치