Skip to content

Instantly share code, notes, and snippets.

@mosluce
Last active May 21, 2018 05:52
Show Gist options
  • Save mosluce/494213158200381bfb370cfcd088c92d to your computer and use it in GitHub Desktop.
Save mosluce/494213158200381bfb370cfcd088c92d to your computer and use it in GitHub Desktop.
public Circle(Vector3 center, Vector3 normal, int polyAmount, float radius)
{
this.normal = normal.normalized;
this.center = center;
var z = Vector3.forward;
var dot = Vector3.Dot(z, normal);
var y = z - dot * normal;
if (dot == 1 || dot == -1)
{
y = Vector3.up;
}
this.vertices = new Vector3[polyAmount];
var delta = 360 / polyAmount;
for (int i = 0; i < polyAmount; i++)
{
this.vertices[i] = Quaternion.AngleAxis(-delta * i, normal) * y.normalized * radius + center;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment