Created
June 5, 2018 00:48
-
-
Save edom18/6e03fe00ac9bc5e5e6f69802031e5fd3 to your computer and use it in GitHub Desktop.
円の外接三角形の頂点計算
This file contains 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
using System.Collections; | |
using System.Collections.Generic; | |
using UnityEngine; | |
public class Test : MonoBehaviour | |
{ | |
[SerializeField] | |
private float _radius = 1f; | |
private Vector3 _center = Vector3.zero; | |
private Vector3 _A, _B, _C; | |
private void Start() | |
{ | |
Calc(); | |
} | |
private void Calc() | |
{ | |
float cx = _center.x; | |
float cy = _center.z; | |
float r = _radius; | |
float r2 = r * 2f; | |
float r3 = r * Mathf.Sqrt(3f); | |
float Ax = (cx - r2); | |
float Ay = (cy - r); | |
float Bx = (cx + r2); | |
float By = (cy - r); | |
float Cx = cx; | |
float Cy = (cy + r3); | |
_A = new Vector3(Ax, 0, Ay); | |
_B = new Vector3(Bx, 0, By); | |
_C = new Vector3(Cx, 0, Cy); | |
} | |
private void OnDrawGizmos() | |
{ | |
if (!Application.isPlaying) | |
{ | |
return; | |
} | |
UnityEditor.Handles.DrawWireDisc(_center, Vector3.up, _radius); | |
Gizmos.color = Color.red; | |
Gizmos.DrawLine(_A, _B); | |
Gizmos.DrawLine(_B, _C); | |
Gizmos.DrawLine(_C, _A); | |
Gizmos.color = Color.cyan; | |
Gizmos.DrawWireSphere(_center, 0.1f); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment