Arc points calculation in spherical coordinates for DMX Moving Head

Next Story

WebRTC many to many video conference with Kurento and Scala Actors

From time to time in the process of developing software engineers come across various mathematical issues. Usually those issues are easy fixes and can be resolved applying elementary mathematics, but sometimes we are facing complex and intriguing task. Please, see below a case study, I hope you find it interesting.

While helping to develop Gunnebo Business Solution product, our customer Bjorn Nostdahl requested to create custom control system to be used for the set of different DMX Lights. You know, those kinds of lights that are being used for huge concerts, TV shows or night clubs.

Arc points calculation in spherical coordinates for DMX Moving Head

One of those lights is DMX Moving Head, it rotates almost to any angle, changes focus, colors, intensity, etc. The customer requested the sun movement simulation on a ceiling, starting from sunrise till sunset to impress conference participants.

Imagine, we would need to calculate light path from point A to point B along the arc. Whereas light can be rotated by 360 degrees vertically and horizontally, anyway we should use spherical coordinate system for points forming the arc.

Arc points calculation in spherical coordinates for DMX Moving Head 2

To start with, let’s try to recall spherical coordinates formulas

Arc points calculation in spherical coordinates for DMX Moving Head 3
Where r > 0, 0 ≤ θ ≤ 2π , 0 ≤ φ ≤ π
Arc points calculation in spherical coordinates for DMX Moving Head 4
Pic.1. Spherical coordinate system

In our case there are three points in spherical coordinates: starting point A, target point B and center point C. All these points belong to the sphere. We don’t care about sphere radius and can use unit sphere for calculation purposes because ray of light does not have physical distance.

The first step is converting all points into Cartesian coordinate system. We’ll use formula 1 for this purpose. JavaScript implementation for Cartesian conversion is the following:

Next we would need to find normal vector for a plane, where points A and B belong. On this stage normal vector will be the equal unit vector vn, which will cross circle center point C. We can calculate normal vector the following way:

Also we need to find the real center point Cc’, which will be a cross point of normal vector vn and the plane where points Ac and Bc belong.

Finally, there are three points describing the plane. We’ll save Cc’ to movement_point  variable and will subtract point Cc’ from every point we have to simplify calculation. We need movement_point point for reverse transformation. After such transformations the point  Cc’ will be positioned in coordinate system center O(0,0,0). And the most interesting point – rotating coordinate system to make AcBcCc’ plane equal Oxy plane. We will use the following formulas (2) for that purpose:


Please, find JavaScript implementation below:

At this stage we can ignore z coordinate and use 2D formulas because point Сс’ is in the coordinate system center and points Ac, Bc belong to Oxy plane. Z coordinate equals zero. Also we calculated backVector. It’s necessary for coordinate system reverse rotation.

As a next step we would need to calculate t-parameter value for points Ac and Bc:

Now, as both sector angle created by points Acr, Bcr, Ccr  and angle step are defined, we could easily calculate circle points coordinates. We’ll find sector angle and iteration step.

The final step is to find point coordinates for each iteration and to make reverse transformation.

That’s it! In this article I outlined how to find Arc point coordinates for circle on the sphere. I hope you will find it helpful one day! 🙂


Leave a Reply

Your email address will not be published. Required fields are marked *