Drawing line border on an arc

Avatar
  • updated
  • Answered

I want to draw a border around an arc shape (I'm using it for a "power meter", and would like a border behind it).  Currently, I'm doing this with an additional arc with a lower draw order that is slightly larger in width so that it peeks out from behind the background of the meter.  The tricky bit is the ends of the border.  To implement that, I'm making the start/end of the border arc slightly larger than the background arc.  The problem is that I'd like a good way of calculating what the proper delta should be to make a consistently sized border.    

For example,  for a meter with a radius of 1, the background thickness is set to 0.3m, with an angle range of 0.0tr to 0.5tr.  The border arc is set to a thickness of .34m, giving an outline along the circumference of .02m on the inside and outside.  I also set the start/end angle range of the border arc to -0.004 tr and 0.504 tr, respectively.  This gives a "nice" look, but has a bit of a problem:  The 'ends' of the arc border are thinner on the inside radius than on the outside radius (as is expected).  This effect is not too noticeable with the meter is small, but as the meter gets larger, it becomes more apparent.  Also, since I want to animate the meters to cover more or less arc, it would be nice to have a consistently sized end-cap line for the meter border rather than some magic "constant" that I add and subtract from the border arc's angle range.

(See attached images -- first image is example arc, second is closeup of left endcap)

Any suggestions?

-- pryankster

Image 544

Image 545

Reporting a bug? please specify Unity version:
Reporting a bug? please specify Shapes version:
Reporting a bug? please specify Render Pipeline:
URP
Avatar
Freya Holmér creator
  • Answered

I would do it with two arcs and two lines - first two arcs for the inner and outer arc, then two lines to cap off the arc with a consistent thickness. otherwise there's no other built-in way of doing this I'm afraid!