Greetings,
I’ve created a script to make a Circle as a mesh. The script, at the moment, has a slider that controls the ‘resolution’ of the circle between 3 and 72.
The resolution of a circle is equal to the number of it’s edges.
Now this is all working really fine. For the exception that several resolutions don’t make a circle.
Like this one, with a resolution of ‘46’
[72456-incompletecircle.png*_|72456]
I think it’s down to the way I find the positions for the vertices of the circle. I just rotate a Vector3 clockwise with Quaternion.AngleAxis. Where the Angle is equal to 360 / Resolution.
Again. some resolutions do work. Like 3, 4, 6, 8, 12, 18, 36 or 72.
Can you help me find a workarround for this problem? I’m willing to provide more info if needed.
Edit: Constructor of the Circle
public Circle(float radius, float border, int offset, int resolution, Direction direction) {
Radius = radius;
Border = border;
Offset = offset;
Resolution = resolution;
Direction = direction;
Vector3 oPoint;
Vector3 rPoint;
Vector3 dir;
switch (Direction) {
default:
oPoint = Vector3.zero;
rPoint = Vector3.zero;
dir = Vector3.forward;
break;
case Direction.Back:
oPoint = new Vector3(Radius + 0.1f, 0.0f, 0.0f);
rPoint = new Vector3(Radius, 0.0f, 0.0f);
dir = Vector3.forward;
break;
case Direction.Forward:
oPoint = new Vector3(-(Radius + 0.1f), 0.0f, 0.0f);
rPoint = new Vector3(-(Radius), 0.0f, 0.0f);
dir = Vector3.back;
break;
case Direction.Left:
oPoint = new Vector3(0.0f, 0.0f, Radius + 0.1f);
rPoint = new Vector3(0.0f, 0.0f, Radius);
dir = Vector3.right;
break;
case Direction.Right:
oPoint = new Vector3(0.0f, 0.0f, -(Radius + 0.1f));
rPoint = new Vector3(0.0f, 0.0f, -(Radius));
dir = Vector3.left;
break;
case Direction.Up:
oPoint = new Vector3(Radius + 0.1f, 0.0f, 0.0f);
rPoint = new Vector3(Radius, 0.0f, 0.0f);
dir = Vector3.down;
break;
case Direction.Down:
oPoint = new Vector3(-(Radius + 0.1f), 0.0f, 0.0f);
rPoint = new Vector3(-(Radius), 0.0f, 0.0f);
dir = Vector3.up;
break;
}
OffsetVector = Quaternion.AngleAxis(Offset, dir) * oPoint;
Vertices = new Vector3[((Resolution + 1) * 2) + 1];
int cVerts = Resolution + 1;
float step = 360 / Resolution;
Vertices[0] = Vector3.zero;
float lerp = Border / Radius;
for (int i = 1; i < Vertices.Length; i++) {
Quaternion rot = Quaternion.AngleAxis(Offset - (step * (i - 1)), dir);
if (i < (cVerts + 1)) Vertices _= rot * rPoint;_
else Vertices = Vector3.Lerp(Vertices[i - cVerts], Vertices[0], lerp);
}
}
_*