# 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. 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. 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: 