數學基礎知識之Sin、cos畫圓
阿新 • • 發佈:2019-02-11
由於在控制檯裡面畫圓的時候,SetCursorPosition該函式只接受Int型別的資料 所以位置就會四捨五入,這樣就畫的不正確 所以採用Uniyt中的2D介面繪製的 主要是鞏固math.sin和math.cos函式
void DrawCircle() { float x = obj.transform.localPosition.x; float y = obj.transform.localPosition.y; float radir = 200; for (int i = 0; i < 90; i++) { //第一象限 Vector3 vc = Vector3.zero; vc.x = x + radir * Mathf.Cos(Mathf.PI / 180 * i); vc.y = y + radir * Mathf.Sin(Mathf.PI / 180 * i); GameObject tmpObj = Instantiate(obj.gameObject); tmpObj.transform.parent = obj.transform.parent; tmpObj.transform.localPosition = vc; tmpObj.transform.localScale = Vector3.one; //第四象限 vc.y = y - radir * Mathf.Sin(Mathf.PI / 180 * i); tmpObj = Instantiate(obj.gameObject); tmpObj.transform.parent = obj.transform.parent; tmpObj.transform.localPosition = vc; tmpObj.transform.localScale = Vector3.one; //第二象限 vc = Vector3.zero; vc.x = x - radir * Mathf.Cos(Mathf.PI / 180 * i); vc.y = y + radir * Mathf.Sin(Mathf.PI / 180 * i); tmpObj = Instantiate(obj.gameObject); tmpObj.transform.parent = obj.transform.parent; tmpObj.transform.localPosition = vc; tmpObj.transform.localScale = Vector3.one; //第三象限 vc.y = y - radir * Mathf.Sin(Mathf.PI / 180 * i); tmpObj = Instantiate(obj.gameObject); tmpObj.transform.parent = obj.transform.parent; tmpObj.transform.localPosition = vc; tmpObj.transform.localScale = Vector3.one; } }