c# - 如何确定两个圆圈是否重叠或接触?

标签 c# unity3d geometry collision-detection

我使用下面的代码围绕我的游戏对象绘制一个圆圈:

using UnityEngine;
 using System.Collections;

 [RequireComponent(typeof(LineRenderer))]
 public class DrawCircle : MonoBehaviour
 {
     [Range(0, 50)]
     public int segments = 50;
     [Range(0, 5)]
     public float xradius = 5;
     [Range(0, 5)]
     public float yradius = 5;
     LineRenderer line;

     void Start()
     {
         line = gameObject.GetComponent<LineRenderer>();
         line.positionCount = segments + 1;
         line.useWorldSpace = false;
         CreatePoints();
     }

     void Update()
     {
         CreatePoints();
     }

     void CreatePoints()
     {
         float x;
         float y;
         float z;

         float angle = 20f;

         for (int i = 0; i < (segments + 1); i++)
         {
             x = Mathf.Sin(Mathf.Deg2Rad * angle) * xradius;
             z = Mathf.Cos(Mathf.Deg2Rad * angle) * yradius;

             line.SetPosition(i, new Vector3(x, 0, z));

             angle += (360f / segments + 1);
         }
     }
 }

假设如果我将这个 Circle 类添加为对象 A 和对象 B 的组件。我将如何确定对象 A 上的圆是否与对象 B 上的圆接触?

最佳答案

如果圆心之间的距离大于其半径之和,则圆不接触。如果它更小,他们会做

关于c# - 如何确定两个圆圈是否重叠或接触?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54390129/

相关文章:

c# - 统一: Need help how to double click detection in c#?

python - 计算船只到海岸或海岸线的距离

assembly - x86汇编语言中点圆算法

c++ - 单位半球表面上快速均匀分布的随机点

c# - 将项目添加到字典返回 System.IndexOutOfRangeException : Index was outside the bounds of the array

c# - 使用 QueryOver 将相关子查询添加到 Select 语句

c# - 使用 Reflection.Emit 动态创建一个类。我被困

android - 统一: JDK stop working

c# - 获取本地时区信息

c# - 如何创建基本字符类的实例