using System.Collections; using System.Collections.Generic; using UnityEngine; public class Hyperbola : MonoBehaviour { Mesh mesh; public Vector3 center; public float a; public float b; // Start is called before the first frame update void Start() { mesh = new Mesh { name = "Hyperbola" }; } // Update is called once per frame void Update() { } public void DrawHyperbola() { mesh.Clear(); Vector3[] vectors = new Vector3[202]; int k = 0; float step = a / 100; float x = -a; while (k < 51) { float y = x * x / (a * a) - 1; y *= (b * b); y = Mathf.Sqrt(y); vectors[50 + k] = new Vector3(x, y, 0); if (y != 0) { vectors[50 - k] = new Vector3(x, -y, 0); } x -= step; step *= 1.1f; k++; } x = a; step = a / 100; k = 0; while (k < 51) { float y = x * x / (a * a) - 1; y *= (b * b); y = Mathf.Sqrt(y); vectors[151 + k] = new Vector3(x, y, 0); if (y != 0) { vectors[151 - k] = new Vector3(x, -y, 0); } x += step; step *= 1.1f; k++; } mesh.vertices = vectors; int[] triangle = new int[400]; for (int i = 0; i < 100; ++i) { triangle[2 * i] = i; triangle[2 * i + 1] = i + 1; } for (int i = 100; i < 200; ++i) { triangle[2 * i] = i + 1; triangle[2 * i + 1] = i + 2; } mesh.SetIndices(triangle, MeshTopology.Lines, 0); GetComponent().mesh = mesh; } }