数学基础知识之Sin、cos画圆

由于在控制台里面画圆的时候,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;

        }

    }

数学基础知识之Sin、cos画圆_第1张图片

你可能感兴趣的:(数学基础知识,unity,sin,cos,mathf)