|
@@ -1,230 +0,0 @@
|
|
|
-using System.Collections;
|
|
|
-using System.Collections.Generic;
|
|
|
-using UnityEngine;
|
|
|
-using UnityEngine.UI;
|
|
|
-
|
|
|
-public class Gongshi2 : MonoBehaviour
|
|
|
-{
|
|
|
-
|
|
|
- public InputField tw;
|
|
|
- public InputField th;
|
|
|
-
|
|
|
- public InputField sceneWidth;
|
|
|
- public InputField sceneLength;
|
|
|
-
|
|
|
- public InputField p2x;
|
|
|
- public InputField p2y;
|
|
|
-
|
|
|
- public InputField p2x2;
|
|
|
- public InputField p2y2;
|
|
|
-
|
|
|
- void Start()
|
|
|
- {
|
|
|
- }
|
|
|
-
|
|
|
- public InputField eul;
|
|
|
- public InputField p3x;
|
|
|
- public InputField p3y;
|
|
|
- public InputField p3Z;
|
|
|
-
|
|
|
- public InputField eul2;
|
|
|
- public InputField p3x2;
|
|
|
- public InputField p3y2;
|
|
|
- public InputField p3Z2;
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
- public void send()
|
|
|
- {
|
|
|
- t.text = "";
|
|
|
- F3Dto2D();
|
|
|
- FEulTo2D();
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
- public float EulChange(float eul)
|
|
|
- {
|
|
|
- if (eul < 0)
|
|
|
- {
|
|
|
- eul = 360 + eul;
|
|
|
- }
|
|
|
- log("eul==>" + eul);
|
|
|
- return eul;
|
|
|
- }
|
|
|
- public void F3Dto2D()
|
|
|
- {
|
|
|
-
|
|
|
-
|
|
|
- Vector2 p3dto2d = new Vector2(-float.Parse(p3x.text), -float.Parse(p3Z.text));
|
|
|
-
|
|
|
- log("p3dto2d==>" + p3dto2d);
|
|
|
-
|
|
|
- float r = Vector3.Distance(p3dto2d, Vector3.zero);
|
|
|
- Debug.Log("r==>" + r);
|
|
|
-
|
|
|
- log("r==>" + r);
|
|
|
-
|
|
|
- float e1 = F2DTOEULJS(p3dto2d, Vector2.zero);
|
|
|
- if (e1 == float.NaN)
|
|
|
- {
|
|
|
- e1 = 0;
|
|
|
- }
|
|
|
- Debug.Log("e1==>" + e1);
|
|
|
-
|
|
|
- log("e1==>" + e1);
|
|
|
-
|
|
|
-
|
|
|
- Vector2 a = new Vector2(r * Mathf.Cos(((e1 - EulChange(float.Parse(eul.text))) * (Mathf.PI * 2) / 360)), r * Mathf.Sin(((e1 - EulChange(float.Parse(eul.text))) * (Mathf.PI * 2) / 360)));
|
|
|
-
|
|
|
- log("a==>" + a);
|
|
|
- Debug.Log("a==>" + a);
|
|
|
-
|
|
|
- a = -a;
|
|
|
-
|
|
|
- log("a==>" + a);
|
|
|
- Debug.Log("-a==>" + a);
|
|
|
-
|
|
|
- p3dto2d = new Vector2(a.x / float.Parse(sceneLength.text) * float.Parse(tw.text), (float.Parse(th.text) - (a.y / float.Parse(sceneWidth.text) * float.Parse(th.text))));
|
|
|
- Debug.Log("p3dto2d==>" + p3dto2d);
|
|
|
-
|
|
|
-
|
|
|
- log("p3dto2d==>" + p3dto2d);
|
|
|
- p2x.text = p3dto2d.x.ToString("F2");
|
|
|
- p2y.text = p3dto2d.y.ToString("F2");
|
|
|
-
|
|
|
-
|
|
|
- }
|
|
|
- public void FEulTo2D()
|
|
|
- {
|
|
|
-
|
|
|
- Vector2 initialPosition = new Vector2(float.Parse(p2x.text), float.Parse(th.text) - float.Parse(p2y.text));
|
|
|
-
|
|
|
- log("initialPosition==>" + initialPosition);
|
|
|
-
|
|
|
- float rotationAngle = EulChange(float.Parse(eul.text));
|
|
|
-
|
|
|
- log("rotationAngle==>" + rotationAngle);
|
|
|
-
|
|
|
- float radians = Mathf.Deg2Rad * rotationAngle;
|
|
|
-
|
|
|
- log("radians==>" + radians);
|
|
|
-
|
|
|
- Vector2 directionVector = new Vector2(Mathf.Cos(radians), Mathf.Sin(radians)) * 100;
|
|
|
- log("directionVector==>" + directionVector);
|
|
|
- Vector2 newPosition = initialPosition + directionVector;
|
|
|
- log("newPosition==>" + newPosition);
|
|
|
- Vector2 newPosition2 = new Vector2(newPosition.x, float.Parse(th.text) - newPosition.y);
|
|
|
-
|
|
|
- Debug.Log("新的坐标:" + newPosition);
|
|
|
- p2x2.text = newPosition2.x.ToString("F2");
|
|
|
- p2y2.text = newPosition2.y.ToString("F2");
|
|
|
-
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
- public float F2DTOEULJS(Vector2 v1, Vector2 v2)
|
|
|
- {
|
|
|
- Vector2 pointA = v1;
|
|
|
- log("pointA==>" + pointA);
|
|
|
- Debug.Log("pointA====>" + pointA);
|
|
|
- Vector2 pointB = v2;
|
|
|
- log("pointB==>" + pointB);
|
|
|
- Debug.Log("pointB====>" + pointB);
|
|
|
- Vector2 pointC = new Vector2(v1.x + 10, v1.y);
|
|
|
- log("pointC==>" + pointC);
|
|
|
- Debug.Log("pointC====>" + pointC);
|
|
|
-
|
|
|
-
|
|
|
- float sideAB = Vector2.Distance(pointA, pointB);
|
|
|
- log("sideAB==>" + sideAB);
|
|
|
- Debug.Log("sideAB====>" + sideAB);
|
|
|
- float sideBC = Vector2.Distance(pointB, pointC);
|
|
|
- log("sideBC==>" + sideBC);
|
|
|
- Debug.Log("sideBC====>" + sideBC);
|
|
|
- float sideCA = Vector2.Distance(pointC, pointA);
|
|
|
- log("sideCA==>" + sideCA);
|
|
|
- Debug.Log("sideCA====>" + sideCA);
|
|
|
- float angleB = 0;
|
|
|
- if ((2f * sideCA * sideAB) != 0)
|
|
|
- {
|
|
|
- angleB = Mathf.Acos((sideCA * sideCA + sideAB * sideAB - sideBC * sideBC) / (2f * sideCA * sideAB));
|
|
|
-
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
- if (angleB == float.NaN)
|
|
|
- {
|
|
|
- angleB = 0;
|
|
|
- }
|
|
|
- log("angleB==>" + angleB);
|
|
|
- if (v1.x > v2.x && v1.y > v2.y)
|
|
|
- {
|
|
|
-
|
|
|
- angleB = 360 - angleB * Mathf.Rad2Deg;
|
|
|
- }
|
|
|
- else if (v1.x < v2.x && v1.y > v2.y)
|
|
|
- {
|
|
|
- angleB = 360 - angleB * Mathf.Rad2Deg;
|
|
|
-
|
|
|
- }
|
|
|
- else
|
|
|
- {
|
|
|
-
|
|
|
- angleB = angleB * Mathf.Rad2Deg;
|
|
|
- }
|
|
|
- log("angleB==>" + angleB);
|
|
|
- return angleB;
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
- public void get()
|
|
|
- {
|
|
|
- t.text = "";
|
|
|
- F2Dto3D();
|
|
|
- }
|
|
|
- public void F2Dto3D()
|
|
|
- {
|
|
|
-
|
|
|
- Vector2 p1 = new Vector2(float.Parse(p2x.text) / float.Parse(tw.text) * float.Parse(sceneLength.text), ((float.Parse(th.text) - (float.Parse(p2y.text))) / float.Parse(th.text) * float.Parse(sceneWidth.text)));
|
|
|
- log("p1==>" + p1);
|
|
|
-
|
|
|
-
|
|
|
- Vector2 p2 = Vector2.zero - p1;
|
|
|
- log("p2==>" + p2);
|
|
|
-
|
|
|
- float e1 = F2DTOEULJS(p2, Vector2.zero);
|
|
|
- log("e1==>" + e1);
|
|
|
-
|
|
|
-
|
|
|
- float r = Vector3.Distance(p2, Vector3.zero);
|
|
|
-
|
|
|
- log("p1==>" + r);
|
|
|
-
|
|
|
-
|
|
|
- Vector3 a = new Vector3(-r * Mathf.Cos((F2DTOEUL() + e1) * (Mathf.PI * 2) / 360), 0, -r * Mathf.Sin((F2DTOEUL() + e1) * (Mathf.PI * 2) / 360));
|
|
|
- p3x2.text = a.x.ToString("F2");
|
|
|
- p3y2.text = a.y.ToString("F2");
|
|
|
- p3Z2.text = a.z.ToString("F2");
|
|
|
- log("a==>" + a);
|
|
|
-
|
|
|
-
|
|
|
- }
|
|
|
- public float F2DTOEUL()
|
|
|
- {
|
|
|
-
|
|
|
- float angleB = F2DTOEULJS(new Vector2(float.Parse(p2x.text), (float.Parse(th.text) - float.Parse(p2y.text))), new Vector2(float.Parse(p2x2.text), float.Parse(th.text) - float.Parse(p2y2.text)));
|
|
|
-
|
|
|
- log("angleB==>" + angleB);
|
|
|
- eul2.text = angleB.ToString("F2");
|
|
|
- Debug.Log("角度 B:" + angleB);
|
|
|
-
|
|
|
- return angleB;
|
|
|
- }
|
|
|
-
|
|
|
- public Text t;
|
|
|
- public void log(object obj)
|
|
|
- {
|
|
|
- t.text += "\n" + obj.ToString();
|
|
|
- }
|
|
|
-
|
|
|
-}
|