Board index FlightGear Development Canvas

Canvas arcs

Canvas is FlightGear's new fully scriptable 2D drawing system that will allow you to easily create new instruments, HUDs and even GUI dialogs and custom GUI widgets, without having to write C++ code and without having to rebuild FlightGear.

Canvas arcs

Postby Alant » Fri Dec 16, 2016 11:20 pm

How can I draw a canvas arc given centre, radius, start angle and finish angle?

http://wiki.flightgear.org/Canvas_Nasal ... SmallCCWTo shows how to draw an arc between two points, but does not seem very helpful. All the examples appear to be at 90 degree intervals, and everything seems to be in cartesian co-ordinates. For an arc I would like to set centre point, radius and angle instead with polar coordinates.

I need to be able to vary the angle at run-time.

TIA

Alan
Alant
 
Posts: 745
Joined: Wed Jun 23, 2010 5:58 am
Location: Portugal
Callsign: Tarnish99
Version: from Git
OS: Windows 10

Re: Canvas arcs

Postby Thorsten » Sat Dec 17, 2016 7:39 am

shows how to draw an arc between two points, but does not seem very helpful.


No? Some trigonometry helps...

center: (c1, c2), radius R, start and stop angles (phi1, phi2)

p1 = (c1 + R * sin(phi1), c2 + R * cos(phi1)
p2 = (c1 + R * sin(phi2), c2 + R * cos(phi2)

-> draw arc from p1 and p2
Thorsten
 
Posts: 9899
Joined: Mon Nov 02, 2009 8:33 am

Re: Canvas arcs

Postby Alant » Sat Dec 17, 2016 9:31 am

Thanks Thorsten, but that seems rather excessive for what I had expected to find as a basic method.

Unless there is a undocumented polar co-ordinates method .I will have to do it that way.

Alan
Alant
 
Posts: 745
Joined: Wed Jun 23, 2010 5:58 am
Location: Portugal
Callsign: Tarnish99
Version: from Git
OS: Windows 10

Re: Canvas arcs

Postby Thorsten » Sat Dec 17, 2016 9:37 am

You can write a wrapper and then you have a basic method... I have lots of self-defined drawing wrappers for what I need in my canvas code (among others curved arc with scale drawer routines).
Thorsten
 
Posts: 9899
Joined: Mon Nov 02, 2009 8:33 am


Return to Canvas

Who is online

Users browsing this forum: No registered users and 4 guests