line - cone intersection

Equation for line (cartesian)

Equation for cone (cartesian)

Assumed to be centred at 0, the coordinate system origin.

0=- z^{2} + \frac{1}{c^{2}} \left(x^{2} + y^{2}\right)

Intersection solutions

Parametric solution (t). Solutions were derived automatically using sympy.

Points in cartesian coordinates (x, y, z)

C Code
x = x0 + (pow(c, 2)*l*z0 - k*y0 - x0 + sqrt(pow(c, 2)*pow(k, 2)*pow(z0, 2) - 2*pow(c, 2)*k*l*y0*z0 + pow(c, 2)*pow(l, 2)*pow(x0, 2) + pow(c, 2)*pow(l, 2)*pow(y0, 2) - 2*pow(c, 2)*l*x0*z0 + pow(c, 2)*pow(z0, 2) - pow(k, 2)*pow(x0, 2) + 2*k*x0*y0 - pow(y0, 2)))/(-pow(c, 2)*pow(l, 2) + pow(k, 2) + 1);
y = k*(pow(c, 2)*l*z0 - k*y0 - x0 + sqrt(pow(c, 2)*pow(k, 2)*pow(z0, 2) - 2*pow(c, 2)*k*l*y0*z0 + pow(c, 2)*pow(l, 2)*pow(x0, 2) + pow(c, 2)*pow(l, 2)*pow(y0, 2) - 2*pow(c, 2)*l*x0*z0 + pow(c, 2)*pow(z0, 2) - pow(k, 2)*pow(x0, 2) + 2*k*x0*y0 - pow(y0, 2)))/(-pow(c, 2)*pow(l, 2) + pow(k, 2) + 1) + y0;
z = l*(pow(c, 2)*l*z0 - k*y0 - x0 + sqrt(pow(c, 2)*pow(k, 2)*pow(z0, 2) - 2*pow(c, 2)*k*l*y0*z0 + pow(c, 2)*pow(l, 2)*pow(x0, 2) + pow(c, 2)*pow(l, 2)*pow(y0, 2) - 2*pow(c, 2)*l*x0*z0 + pow(c, 2)*pow(z0, 2) - pow(k, 2)*pow(x0, 2) + 2*k*x0*y0 - pow(y0, 2)))/(-pow(c, 2)*pow(l, 2) + pow(k, 2) + 1) + z0;
x = x0 + (-pow(c, 2)*l*z0 + k*y0 + x0 + sqrt(pow(c, 2)*pow(k, 2)*pow(z0, 2) - 2*pow(c, 2)*k*l*y0*z0 + pow(c, 2)*pow(l, 2)*pow(x0, 2) + pow(c, 2)*pow(l, 2)*pow(y0, 2) - 2*pow(c, 2)*l*x0*z0 + pow(c, 2)*pow(z0, 2) - pow(k, 2)*pow(x0, 2) + 2*k*x0*y0 - pow(y0, 2)))/(pow(c, 2)*pow(l, 2) - pow(k, 2) - 1);
y = k*(-pow(c, 2)*l*z0 + k*y0 + x0 + sqrt(pow(c, 2)*pow(k, 2)*pow(z0, 2) - 2*pow(c, 2)*k*l*y0*z0 + pow(c, 2)*pow(l, 2)*pow(x0, 2) + pow(c, 2)*pow(l, 2)*pow(y0, 2) - 2*pow(c, 2)*l*x0*z0 + pow(c, 2)*pow(z0, 2) - pow(k, 2)*pow(x0, 2) + 2*k*x0*y0 - pow(y0, 2)))/(pow(c, 2)*pow(l, 2) - pow(k, 2) - 1) + y0;
z = l*(-pow(c, 2)*l*z0 + k*y0 + x0 + sqrt(pow(c, 2)*pow(k, 2)*pow(z0, 2) - 2*pow(c, 2)*k*l*y0*z0 + pow(c, 2)*pow(l, 2)*pow(x0, 2) + pow(c, 2)*pow(l, 2)*pow(y0, 2) - 2*pow(c, 2)*l*x0*z0 + pow(c, 2)*pow(z0, 2) - pow(k, 2)*pow(x0, 2) + 2*k*x0*y0 - pow(y0, 2)))/(pow(c, 2)*pow(l, 2) - pow(k, 2) - 1) + z0;

Distance inside

Distance between crossing points.

2 \left\lvert{\frac{1}{- c^{2} l^{2} + k^{2} + 1} \sqrt{c^{2} k^{2} z_{0}^{2} - 2 c^{2} k l y_{0} z_{0} + c^{2} l^{2} x_{0}^{2} + c^{2} l^{2} y_{0}^{2} - 2 c^{2} l x_{0} z_{0} + c^{2} z_{0}^{2} - k^{2} x_{0}^{2} + 2 k x_{0} y_{0} - y_{0}^{2}}}\right\rvert

C Code

sol1 = (pow(c, 2)*l*z0 - k*y0 - x0 + sqrt(pow(c, 2)*pow(k, 2)*pow(z0, 2) - 2*pow(c, 2)*k*l*y0*z0 + pow(c, 2)*pow(l, 2)*pow(x0, 2) + pow(c, 2)*pow(l, 2)*pow(y0, 2) - 2*pow(c, 2)*l*x0*z0 + pow(c, 2)*pow(z0, 2) - pow(k, 2)*pow(x0, 2) + 2*k*x0*y0 - pow(y0, 2)))/(-pow(c, 2)*pow(l, 2) + pow(k, 2) + 1);
sol2 = (-pow(c, 2)*l*z0 + k*y0 + x0 + sqrt(pow(c, 2)*pow(k, 2)*pow(z0, 2) - 2*pow(c, 2)*k*l*y0*z0 + pow(c, 2)*pow(l, 2)*pow(x0, 2) + pow(c, 2)*pow(l, 2)*pow(y0, 2) - 2*pow(c, 2)*l*x0*z0 + pow(c, 2)*pow(z0, 2) - pow(k, 2)*pow(x0, 2) + 2*k*x0*y0 - pow(y0, 2)))/(pow(c, 2)*pow(l, 2) - pow(k, 2) - 1);
distance = 2*fabs(sqrt(pow(c, 2)*pow(k, 2)*pow(z0, 2) - 2*pow(c, 2)*k*l*y0*z0 + pow(c, 2)*pow(l, 2)*pow(x0, 2) + pow(c, 2)*pow(l, 2)*pow(y0, 2) - 2*pow(c, 2)*l*x0*z0 + pow(c, 2)*pow(z0, 2) - pow(k, 2)*pow(x0, 2) + 2*k*x0*y0 - pow(y0, 2))/(-pow(c, 2)*pow(l, 2) + pow(k, 2) + 1));

Equation for line (spherical)

Equation for cone (cartesian)

Assumed to be centred at 0, the coordinate system origin.

0=- z^{2} + \frac{1}{c^{2}} \left(x^{2} + y^{2}\right)

Intersection solutions

Parametric solution (t). Solutions were derived automatically using sympy.

Points in cartesian coordinates (x, y, z)

C Code
x = x0 + (pow(c, 2)*z0*cos(theta) - x0*sin(theta)*cos(phi) - y0*sin(phi)*sin(theta) + sqrt(-pow(c, 2)*pow(x0, 2)*pow(sin(theta), 2) + pow(c, 2)*pow(x0, 2) - 2*pow(c, 2)*x0*z0*sin(theta)*cos(phi)*cos(theta) - pow(c, 2)*pow(y0, 2)*pow(sin(theta), 2) + pow(c, 2)*pow(y0, 2) - 2*pow(c, 2)*y0*z0*sin(phi)*sin(theta)*cos(theta) + pow(c, 2)*pow(z0, 2)*pow(sin(theta), 2) - pow(x0, 2)*pow(sin(phi), 2)*pow(sin(theta), 2) + 2*x0*y0*sin(phi)*pow(sin(theta), 2)*cos(phi) + pow(y0, 2)*pow(sin(phi), 2)*pow(sin(theta), 2) - pow(y0, 2)*pow(sin(theta), 2)))*sin(theta)*cos(phi)/(-pow(c, 2)*pow(cos(theta), 2) - pow(cos(theta), 2) + 1);
y = y0 + (pow(c, 2)*z0*cos(theta) - x0*sin(theta)*cos(phi) - y0*sin(phi)*sin(theta) + sqrt(-pow(c, 2)*pow(x0, 2)*pow(sin(theta), 2) + pow(c, 2)*pow(x0, 2) - 2*pow(c, 2)*x0*z0*sin(theta)*cos(phi)*cos(theta) - pow(c, 2)*pow(y0, 2)*pow(sin(theta), 2) + pow(c, 2)*pow(y0, 2) - 2*pow(c, 2)*y0*z0*sin(phi)*sin(theta)*cos(theta) + pow(c, 2)*pow(z0, 2)*pow(sin(theta), 2) - pow(x0, 2)*pow(sin(phi), 2)*pow(sin(theta), 2) + 2*x0*y0*sin(phi)*pow(sin(theta), 2)*cos(phi) + pow(y0, 2)*pow(sin(phi), 2)*pow(sin(theta), 2) - pow(y0, 2)*pow(sin(theta), 2)))*sin(phi)*sin(theta)/(-pow(c, 2)*pow(cos(theta), 2) - pow(cos(theta), 2) + 1);
z = z0 + (pow(c, 2)*z0*cos(theta) - x0*sin(theta)*cos(phi) - y0*sin(phi)*sin(theta) + sqrt(-pow(c, 2)*pow(x0, 2)*pow(sin(theta), 2) + pow(c, 2)*pow(x0, 2) - 2*pow(c, 2)*x0*z0*sin(theta)*cos(phi)*cos(theta) - pow(c, 2)*pow(y0, 2)*pow(sin(theta), 2) + pow(c, 2)*pow(y0, 2) - 2*pow(c, 2)*y0*z0*sin(phi)*sin(theta)*cos(theta) + pow(c, 2)*pow(z0, 2)*pow(sin(theta), 2) - pow(x0, 2)*pow(sin(phi), 2)*pow(sin(theta), 2) + 2*x0*y0*sin(phi)*pow(sin(theta), 2)*cos(phi) + pow(y0, 2)*pow(sin(phi), 2)*pow(sin(theta), 2) - pow(y0, 2)*pow(sin(theta), 2)))*cos(theta)/(-pow(c, 2)*pow(cos(theta), 2) - pow(cos(theta), 2) + 1);
x = x0 + (-pow(c, 2)*z0*cos(theta) + x0*sin(theta)*cos(phi) + y0*sin(phi)*sin(theta) + sqrt(-pow(c, 2)*pow(x0, 2)*pow(sin(theta), 2) + pow(c, 2)*pow(x0, 2) - 2*pow(c, 2)*x0*z0*sin(theta)*cos(phi)*cos(theta) - pow(c, 2)*pow(y0, 2)*pow(sin(theta), 2) + pow(c, 2)*pow(y0, 2) - 2*pow(c, 2)*y0*z0*sin(phi)*sin(theta)*cos(theta) + pow(c, 2)*pow(z0, 2)*pow(sin(theta), 2) - pow(x0, 2)*pow(sin(phi), 2)*pow(sin(theta), 2) + 2*x0*y0*sin(phi)*pow(sin(theta), 2)*cos(phi) + pow(y0, 2)*pow(sin(phi), 2)*pow(sin(theta), 2) - pow(y0, 2)*pow(sin(theta), 2)))*sin(theta)*cos(phi)/(pow(c, 2)*pow(cos(theta), 2) + pow(cos(theta), 2) - 1);
y = y0 + (-pow(c, 2)*z0*cos(theta) + x0*sin(theta)*cos(phi) + y0*sin(phi)*sin(theta) + sqrt(-pow(c, 2)*pow(x0, 2)*pow(sin(theta), 2) + pow(c, 2)*pow(x0, 2) - 2*pow(c, 2)*x0*z0*sin(theta)*cos(phi)*cos(theta) - pow(c, 2)*pow(y0, 2)*pow(sin(theta), 2) + pow(c, 2)*pow(y0, 2) - 2*pow(c, 2)*y0*z0*sin(phi)*sin(theta)*cos(theta) + pow(c, 2)*pow(z0, 2)*pow(sin(theta), 2) - pow(x0, 2)*pow(sin(phi), 2)*pow(sin(theta), 2) + 2*x0*y0*sin(phi)*pow(sin(theta), 2)*cos(phi) + pow(y0, 2)*pow(sin(phi), 2)*pow(sin(theta), 2) - pow(y0, 2)*pow(sin(theta), 2)))*sin(phi)*sin(theta)/(pow(c, 2)*pow(cos(theta), 2) + pow(cos(theta), 2) - 1);
z = z0 + (-pow(c, 2)*z0*cos(theta) + x0*sin(theta)*cos(phi) + y0*sin(phi)*sin(theta) + sqrt(-pow(c, 2)*pow(x0, 2)*pow(sin(theta), 2) + pow(c, 2)*pow(x0, 2) - 2*pow(c, 2)*x0*z0*sin(theta)*cos(phi)*cos(theta) - pow(c, 2)*pow(y0, 2)*pow(sin(theta), 2) + pow(c, 2)*pow(y0, 2) - 2*pow(c, 2)*y0*z0*sin(phi)*sin(theta)*cos(theta) + pow(c, 2)*pow(z0, 2)*pow(sin(theta), 2) - pow(x0, 2)*pow(sin(phi), 2)*pow(sin(theta), 2) + 2*x0*y0*sin(phi)*pow(sin(theta), 2)*cos(phi) + pow(y0, 2)*pow(sin(phi), 2)*pow(sin(theta), 2) - pow(y0, 2)*pow(sin(theta), 2)))*cos(theta)/(pow(c, 2)*pow(cos(theta), 2) + pow(cos(theta), 2) - 1);

Distance inside

Distance between crossing points.

2 \left\lvert{\frac{1}{c^{2} \cos^{2}{\left (\theta \right )} + \cos^{2}{\left (\theta \right )} - 1} \sqrt{- c^{2} x_{0}^{2} \sin^{2}{\left (\theta \right )} + c^{2} x_{0}^{2} - \frac{x_{0} z_{0}}{2} c^{2} \left(- \sin{\left (\phi - 2 \theta \right )} + \sin{\left (\phi + 2 \theta \right )}\right) - c^{2} y_{0}^{2} \sin^{2}{\left (\theta \right )} + c^{2} y_{0}^{2} - \frac{y_{0} z_{0}}{2} c^{2} \left(\cos{\left (\phi - 2 \theta \right )} - \cos{\left (\phi + 2 \theta \right )}\right) + c^{2} z_{0}^{2} \sin^{2}{\left (\theta \right )} - x_{0}^{2} \sin^{2}{\left (\phi \right )} \sin^{2}{\left (\theta \right )} + 2 x_{0} y_{0} \sin{\left (\phi \right )} \sin^{2}{\left (\theta \right )} \cos{\left (\phi \right )} + y_{0}^{2} \sin^{2}{\left (\phi \right )} \sin^{2}{\left (\theta \right )} - y_{0}^{2} \sin^{2}{\left (\theta \right )}}}\right\rvert

C Code

sol1 = (pow(c, 2)*z0*cos(theta) - x0*sin(theta)*cos(phi) - y0*sin(phi)*sin(theta) + sqrt(-pow(c, 2)*pow(x0, 2)*pow(sin(theta), 2) + pow(c, 2)*pow(x0, 2) - 2*pow(c, 2)*x0*z0*sin(theta)*cos(phi)*cos(theta) - pow(c, 2)*pow(y0, 2)*pow(sin(theta), 2) + pow(c, 2)*pow(y0, 2) - 2*pow(c, 2)*y0*z0*sin(phi)*sin(theta)*cos(theta) + pow(c, 2)*pow(z0, 2)*pow(sin(theta), 2) - pow(x0, 2)*pow(sin(phi), 2)*pow(sin(theta), 2) + 2*x0*y0*sin(phi)*pow(sin(theta), 2)*cos(phi) + pow(y0, 2)*pow(sin(phi), 2)*pow(sin(theta), 2) - pow(y0, 2)*pow(sin(theta), 2)))/(-pow(c, 2)*pow(cos(theta), 2) - pow(cos(theta), 2) + 1);
sol2 = (-pow(c, 2)*z0*cos(theta) + x0*sin(theta)*cos(phi) + y0*sin(phi)*sin(theta) + sqrt(-pow(c, 2)*pow(x0, 2)*pow(sin(theta), 2) + pow(c, 2)*pow(x0, 2) - 2*pow(c, 2)*x0*z0*sin(theta)*cos(phi)*cos(theta) - pow(c, 2)*pow(y0, 2)*pow(sin(theta), 2) + pow(c, 2)*pow(y0, 2) - 2*pow(c, 2)*y0*z0*sin(phi)*sin(theta)*cos(theta) + pow(c, 2)*pow(z0, 2)*pow(sin(theta), 2) - pow(x0, 2)*pow(sin(phi), 2)*pow(sin(theta), 2) + 2*x0*y0*sin(phi)*pow(sin(theta), 2)*cos(phi) + pow(y0, 2)*pow(sin(phi), 2)*pow(sin(theta), 2) - pow(y0, 2)*pow(sin(theta), 2)))/(pow(c, 2)*pow(cos(theta), 2) + pow(cos(theta), 2) - 1);
distance = 2*fabs(sqrt(-pow(c, 2)*pow(x0, 2)*pow(sin(theta), 2) + pow(c, 2)*pow(x0, 2) - 1.0L/2.0L*pow(c, 2)*x0*z0*(-sin(phi - 2*theta) + sin(phi + 2*theta)) - pow(c, 2)*pow(y0, 2)*pow(sin(theta), 2) + pow(c, 2)*pow(y0, 2) - 1.0L/2.0L*pow(c, 2)*y0*z0*(cos(phi - 2*theta) - cos(phi + 2*theta)) + pow(c, 2)*pow(z0, 2)*pow(sin(theta), 2) - pow(x0, 2)*pow(sin(phi), 2)*pow(sin(theta), 2) + 2*x0*y0*sin(phi)*pow(sin(theta), 2)*cos(phi) + pow(y0, 2)*pow(sin(phi), 2)*pow(sin(theta), 2) - pow(y0, 2)*pow(sin(theta), 2))/(pow(c, 2)*pow(cos(theta), 2) + pow(cos(theta), 2) - 1));


By Johannes Buchner | Source code: https://github.com/JohannesBuchner/intersection | Open a issue or pull request if you would like somthing added