I am getting an unexpected result from Vector3.Distance function, could someone please explain what is going on here:
I create two vectors using two angles and a radius, when angles are 0 and 360 degrees, I expected the distance to be 0, but it is not. Here is the code:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
[ExecuteInEditMode]
public class test : MonoBehaviour
{
public float angle1 = 0f;
public float angle2 = 360f;
public float radius = 1f;
private Vector3 position1, position2;
// Update is called once per frame
void Update()
{
// calculate position vector from given angle
position1 = new Vector3(0, Mathf.Sin(Mathf.Deg2Rad * angle1), Mathf.Cos(Mathf.Deg2Rad * angle1)) * radius;
position2 = new Vector3(0, Mathf.Sin(Mathf.Deg2Rad * angle2), Mathf.Cos(Mathf.Deg2Rad * angle2)) * radius;
float distance = Vector3.Distance(position1, position2);
print("angle1: " + angle1 + " angle2: " + angle2);
print("pos1: " + position1 + " pos2: " + position2);
print("positions equal: " + (position1 == position2));
print("distance: " + distance);
}
}
This outputs the following:
angle1: 0 angle2: 360
pos1: (0.0, 0.0, 1.0) pos2: (0.0, 0.0, 1.0)
positions equal: True
distance: 1.748456E-07
Any help is apprecited.