# Sphere & Elliptical intersection by opening angles and radius

- Author:
- Shawn Featherly

- Topic:
- Angles, Cone, Curve Sketching, Ellipse, Equations, Function Graph, Intersection, Sphere

An ellipse can be warped to lay on the surface of a sphere by intersecting a sphere of radius r with an elliptical cone with an opening angle of along one axis and along a perpendicular axis.
Using a single value as the opening angle specification, the elliptic cone equation is
.

## phi as a Function of theta

## General Parametric Equations in Terms of a, b, tan(Phi) and r

In the general case for given where is the cone angle at the major axis, we have
Note that with the above function for will give terms of the form which is just similarly is making the parameterized functions
and the y function is then
and the z function is
.

## The Relative Value of a and b

The major and minor (semi- technically) axis values and which could be defined to be canonical values at altitude , are not independently significant to the character of an elliptic cone. The major opening angle and minor opening angle are constants of the elliptic cone and their ratio specifies the ratio of to . The equations are more cleanly written in terms of which is also . (Note that is also the major opening angle in the two opening angle discussion . At some point it seems like a good idea to characterize the elliptic cone by the two constants that characterize it in the original discussion.)
The ratio improved equations are
Note they all have a common denominator

*the*opening angle we have been writing## Sanity Check, a=b should revert to circular cone

Expect to get back the circular cone sphere intersection curve functions when . Recall that those functions are parametric flat circle at altitude Z.
for parameter .
A flat circle with radius at altitude .
The elliptic functions are
and
Setting (and )
similarly
and
Sanity check passed.

## Eccentricity, Second and First

Use the second eccentricity and the trigonometric identity to simplify the elliptic cone and intersection curve expressions.
By the way, the first eccentricity is defined by and shows up in the analogous derivation for the elliptic cone when done along the minor axis instead of the major axis shown above. The resulting parametric functions, which are equivalent, involve parameters and instead of and .
The major and minor opening angles, and respectively, fundamentally characterize an elliptic cone. The eccentricities can easily be obtained using and .

## Applet

The functions above are deployed in the applet below and full page in https://www.geogebra.org/3d/p2dfmdg4 .
- The black curve line is the ellipse warped to the surface of a sphere
- Slider j represents the major axis opening angle
- Slider n represents the minor axis opening angle
- Slider r represents the radius of the sphere

## Implemented as Unity3D specific C# code

This could be implemented in any 3D rendering engine. If this was implemented in code for Unity 3D it could look as follows:

```
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
///
/// Projects an outline of an angle from the center of a sphere to its surface.
/// The angle is a cone (or elliptic cone) intersecting with the spheres surface.
///
[RequireComponent(typeof(LineRenderer))]
public class AngleSphereIntersection : MonoBehaviour {
// Number of sides of the polygon representing the warped ellipse. Bigger numbers for less jagged.
private const int positionCount = 0x100;
[Tooltip("The ellipse will be drawn on the surface of a sphere, this defines the size of that sphere")]
[Range(0, 2f)]
public float radius = 1f;
[Tooltip("Angle from the center of the ellipse to its radius's as seen by the center of the sphere")]
[Range(1f, 89f)]
public float angleXAxis = 45, angleYAxis = 45;
[Tooltip("Component that will house the vertices and handle rendering")]
public LineRenderer lineRenderer;
private void Start() {
OnValidate();
}
private void OnValidate() {
DrawEllipse();
}
///
/// Set the points of a LineRenderer to follow the path of a sphere and elliptical cone intersection
///
private void DrawEllipse() {
float xAxisRadians = angleXAxis * Mathf.Deg2Rad;
float yAxisRadians = angleYAxis * Mathf.Deg2Rad;
float currentStep = 0; // what step we are on going around the ellipse of intersection
Vector3 v;
// Shared denominator function of the sphere and elliptical cone intersection.
float tanX = Mathf.Tan(xAxisRadians);
float tanX2 = Mathf.Pow(tanX, 2) + 1;
float abRatio = Mathf.Pow(tanX / Mathf.Tan(yAxisRadians), 2) - 1;
System.Func denominator = step => Mathf.Sqrt(tanX2 + abRatio * Mathf.Pow(Mathf.Sin(step), 2));
// coefficients for the axes the ellipses opens along
float sideAxis = radius * Mathf.Tan(xAxisRadians);
// find the intersection as per https://www.geogebra.org/m/p2dfmdg4
float centerStep;
for(int i = 0; i < positionCount; ++i) {
currentStep = Mathf.Lerp(0, 2 * Mathf.PI, (float)i / positionCount);
// determine position of next point
v.x = sideAxis * Mathf.Cos(currentStep) / denominator(currentStep);
v.y = sideAxis * Mathf.Sin(currentStep) / denominator(currentStep);
centerStep = Mathf.Sqrt(1 + abRatio * Mathf.Pow(Mathf.Sin(currentStep), 2));
v.z = radius * centerStep / denominator(currentStep);
// apply position to the lineRenderer
lineRenderer.SetPosition(i, v);
}
}
}
```