1
\$\begingroup\$

I know circle formula and know how to draw it. but I want put 4 points on it with equal distance from each other. how can I do that?

I work with unity.

\$\endgroup\$
2
2
\$\begingroup\$

It sounds like you want to make a regular polygon. It also sounds like you're talking about 2D space, but just for fun, here's a way to do that for any number of points and any arbitrary circle in 3D space:

public Vector3[] circlePoints (int n, float radius, Vector3 center, Vector3 normal) {
    var points = new Vector3[n];

    Vector3 offset = Vector3.ProjectOnPlane(Vector3.right, normal).normalized * radius;
    float angle = 0;

    for (int i = 0; i < n; i++) {
        Vector3 rotatedOffset = Quaternion.AngleAxis(angle, normal) * offset;
        points[i] = center + rotatedOffset;

        angle += 360f / n;
    }

    return points;
}

Set normal so that it's perpendicular to the circle you want to draw on. So if your game is 2D, use Vector3.forward, since that's perpendicular to the XY plane.

However, for a 2D game or one where every circle is on the same (axis-aligned) plane, I would just go with a trigonometric solution.

\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.