2
\$\begingroup\$

I'd like to draw an arc between two specific angles. For example, "draw an angle between 0 and 90 degrees" and it will draw only that part of the circle and ignore the rest.

\$\endgroup\$
4
\$\begingroup\$

You can define an arc with a radius and start and end angle. Then you simply need to create a series of points to define the arc.

List<Vector2> arcPoints = new List<Vector2>();
float angle = startAngle;
float arcLength = endAngle - startAngle;
for (int i = 0; i <= segments; i++)
{
    float x = Mathf.Sin(Mathf.Deg2Rad * angle) * radius;
    float y = Mathf.Cos(Mathf.Deg2Rad * angle) * radius;

    arcPoints.Add(new Vector2(x,y));

    angle += (arcLength / segments);
}

This example creates a list of points that define an arc. The arc can be made "smoother" by increasing the number of segments.

Drawing the arc is your choice, you can create a mesh, use the LineRenderer or something like GL.LINES.

\$\endgroup\$
  • \$\begingroup\$ Thanks for the answer. Will this algorithme achieve something like this : bit.ly/2aZBvwk Or I will get a pizza-like shape ? (for reference I want to do something like the image) \$\endgroup\$ – PL Audet Aug 17 '16 at 17:42
  • 1
    \$\begingroup\$ This algorithm simply defines the points that make up the arc. It's up to you to decide how to render them. The LineRenderer would probably be the easiest option for what you want. Just set the LineRenderer's points to the ones generated in the algorithm above. \$\endgroup\$ – MichaelHouse Aug 17 '16 at 17:44
  • \$\begingroup\$ Thansk for your help. \$\endgroup\$ – PL Audet Aug 17 '16 at 17:46
  • \$\begingroup\$ Mind if i ask another question ? :What I want to to draw these line relatively to my transform ? \$\endgroup\$ – PL Audet Aug 17 '16 at 23:51
  • \$\begingroup\$ Add the position of the transform to each of the arc points. \$\endgroup\$ – MichaelHouse Aug 18 '16 at 1:35

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.