Magic Lantern Forum

Developing Magic Lantern => Modules Development => Topic started by: ewinemiller on September 11, 2016, 07:17:27 PM

Title: Tilt Calculator module (
Post by: ewinemiller on September 11, 2016, 07:17:27 PM
Hi folks,

Posted here for feedback and suggestions; a module to calculate the appropriate tilt for tilt-shift lenses. Modeled after an android app I did a while back. Much quicker just to bring it up on the camera.

It puts a menu on the Debug tab.


Code: [Select]
Tilt Calculator

Tilt-shift lenses give amazing control of the depth of field by rotating the focus plane, but without knowing how much tilt to dial in, focusing can be frustrating and time consuming.
Tilt Calculator finds the tilt given your focal length and distance to the hinge point. No more trial and error focusing with your tilt-shift. Focus where you want it.

:Author: Eric Winemiller
:License: GPL
:Summary: Tilt Calculator


Code: [Select]
#include <module.h>
#include <dryos.h>
#include <menu.h>
#include <config.h>
#include <math.h>

static uint32_t focal_lengths[] = { 17, 24, 45, 90 };
#define FOCAL_LENGTH_TEXT "17mm", "24mm", "45mm", "90mm"

static float units[] = {10, 25.4, 304.8};
#define UNITS_TEXT "cm", "inch", "feet"

static CONFIG_INT("tilt.calculator.focallength", focal_length_sel, 1);
static CONFIG_INT("tilt.calculator.unit", unit_sel, 1);
static CONFIG_INT("tilt.calculator.distance", distance_sel, 60);

static MENU_UPDATE_FUNC(degrees_update)
double height = distance_sel * units[unit_sel];
int degrees = roundf(1800.0f / M_PI * asinf(focal_lengths[focal_length_sel]/height));
MENU_SET_VALUE("%d.%d degrees", degrees/10, degrees%10);

static struct menu_entry tilt_calc_menu[] =
        .name = "Tilt Calculator",
        .select = menu_open_submenu,
        .submenu_width = 710,
        .children =  (struct menu_entry[])
                .name = "Focal Length",
                .priv = &focal_length_sel,
                .min = 0,
                .max = COUNT(focal_lengths)-1,
                .choices = CHOICES(FOCAL_LENGTH_TEXT),
                .help = "Select the lens focal length.",
                .name = "Unit",
                .priv = &unit_sel,
                .min = 0,
                .max = COUNT(units)-1,
                .choices = CHOICES(UNITS_TEXT),
                .help = "Select the unit for distance to hinge point.",
                .name = "Distance",
                .priv = &distance_sel,
                .min = 1,
                .max = 500,
                .help = "Select the distance to hinge point.",
                .name = "Tilt degrees",
                .update = degrees_update,
                .icon_type = IT_ALWAYS_ON,
                .help  = "[READ-ONLY] Set your tilt to this value.",

static unsigned int tilt_calc_init()
    menu_add("Debug", tilt_calc_menu, COUNT(tilt_calc_menu));
return 0;

static unsigned int tilt_calc_deinit()
menu_remove("Debug", tilt_calc_menu, COUNT(tilt_calc_menu));
return 0;



Title: Re: Tilt Calculator module (
Post by: ewinemiller on September 17, 2016, 01:31:01 AM
Hi folks,

I've posted the compiled version at (

and the source is now available at (

It's only been tested on a 5D mark III.

Are there any tilt-shift enthusiasts watching?

Right now it lets you pick from the four canon lenses, but there are a handful of off brands at different focal lengths (e.g. 35, 80). Any input on just trying to find all those for a short list vs. just letting you pick anything from any focal length 8-200? ML's menu scrolling works really nice so a big list like that is not as bad as it sounds. I'm leaning towards the later.

Title: Re: Tilt Calculator module (
Post by: jrumans on September 17, 2016, 05:12:11 AM
I just purchased the Canon 24mm TS-E II, will definitely check this out, thanks!
Title: Re: Tilt Calculator module (
Post by: garry23 on September 17, 2016, 08:18:37 AM

Great to see you experimenting. Like you I have a 5DIII and I have a 24 TS-E II.

I've posted about my experiences with this lens on my blog, eg (

I did experiment with a Lua script to handle the simple DoF math, but in the end decided it wasn't worth the trouble, and now use the a simple approach of starting with a calc in my head (9/2J).

The reason being that the 35mm Tilt Shift at 24mm doesn't give you any refined access to tilting; and no feedback, like a dof on a non-tilt lens. The focusing process with the TS-E requires much iteration, eg using LV, that I found a tilt calculation beyond the 9/2J level not worth it.

The real value of ML with a TS-E is to use A-ETTR for exposure setting.

I offer the above as my experiences.


Title: Re: Tilt Calculator module (
Post by: DeafEyeJedi on September 29, 2016, 06:30:08 PM
Nice work @ewinemiller and thanks for sharing a compiled version for 5D3. Definitely will give this a test run as I can borrow a 24mm TS-E II from where I work.
Title: Re: Tilt Calculator module (
Post by: ewinemiller on January 03, 2017, 01:47:42 AM
Hi all,

I updated this so that it starts with the canon focal lengths, but you can add and remove focal lengths now up to 10. The links in the second post are updated with the appropriate code and compiled module. It's been tested on 5D3 1.13.

Title: Re: Tilt Calculator module (
Post by: Seanc on January 07, 2019, 03:15:48 PM
Very slick. Thanks!
I'm learning for the first time with an inexpensive Ukrainian 80mm T/S and this is helping me get started. The ability to customize the lens list is perfect. I'm using it just above the subject (pinball playfield) and this helped me zero in on the tilt amount to use.
Title: Re: Tilt Calculator module (
Post by: ewinemiller on July 19, 2020, 01:24:11 PM
Until the where we land for source control question is settled, the code is squirreled away at