Intersection between line and cylinder

In summary, the speaker is trying to find an expression that will work for a "line-to-cylinder intersection" by substituting the equations for a line into the equation for a sphere. However, the resulting equations do not seem to work and the speaker is looking for feedback on the math or logic behind the equations. They are also trying to clarify some of the variables and equations used in the conversation.
  • #1
Joacim Jacobsen
3
0
I have an expression for a "line- to sphere intersection" that works:
a = 1 + Ax^2 + Ay^2
b = 2*(-zs + Ax*(Bx-xs) + Ay*(By-ys))
c = zs^2 + (Bx-xs)^2 + (By - ys)^2 - R^2

This is part of a code in Matlab, and works fine. It is derived from substituting (x=Ax*z+Bx, y=Ay*z+By) into:
((x-xs)^2+(y-ys)^2+(z-zs)^2 = R

I am now trying to do the same for a cylinder, by substituting(x=Ax*z+Bx, y=Ay*z+By) into: (x-xs)^2+(y-ys)^2 = R
Ending up with:
a = Ax^2+Ay^2;
b = 2*Ax*Bx - 2*Ax*xs + 2*Ay*By - 2*Ay*ys;
c = -2*Bx*xs - 2*By*ys + Bx^2 + By^2 + xs^2+ys^2 - R^2;

This doesn't seem to work. Can anyone tell me if something seems off with the math or logic?
Any comments at all would be greatly appreciated.
 
Last edited:
Mathematics news on Phys.org
  • #2
Joacim Jacobsen said:
I have an expression for a "line- to sphere intersection" that works:
a = 1 + Ax^2 + Ay^2
b = 2*(-zs + Ax*(Bx-xs) + Ay*(By-ys))
c = zs^2 + (Bx-xs)^2 + (By - ys)^2 - R^2
Without any supplemental explanation, this doesn't make much sense. A line and a sphere in space can intersect in one of three ways:
1. No intersection
2. Exactly one point of intersection (the line is tangent to the sphere)
3. Two points of intersection

In your equations above, what are a, b, and c?
How did you get these equations?
Joacim Jacobsen said:
This is part of a code in Matlab, and works fine. It is derived from substituting (x=Ax*z+Bx, y=Ay*z+By) into:
((x-xs)^2+(y-ys)^2+(z-zs)^2 = R
Again, with no explanation, this doesn't make much sense.

By the way, the equation of a sphere of radius R, with center at the point ##(x_0, y_0, z_0)## is ##(x - x_0)^2 + (y - y_0)^2 + (x - z_0)^2 = R^2##. In your equation above it looks like you are using just R.
Joacim Jacobsen said:
I am now trying to do the same for a cylinder, by substituting(x=Ax*z+Bx, y=Ay*z+By) into: (x-xs)^2+(y-ys)^2 = R
Ending up with:
a = Ax^2+Ay^2;
b = 2*Ax*Bx - 2*Ax*xs + 2*Ay*By - 2*Ay*ys;
c = -2*Bx*xs - 2*By*ys + Bx^2 + By^2 + xs^2+ys^2 - R^2;

This doesn't seem to work. Can anyone tell me if something seems off with the math or logic?
Any comments at all would be greatly appreciated.
A line and a cylinder in space can intersect in one of four ways:
1. No intersection
2. Exactly one point of intersection (the line is tangent to the cylinder)
3. Two points of intersection
4. An infinite number of points of intersection (the line is parallel to the cylinder's axis and lies on the cylinder)
 
  • #3
Ok, thank you for your reply!

For the first two questions: I got a,b and c from putting the equation for a line into the equation for a sphere. I ended up with a quadratic equation when I solved for "Az". a,b and c are simply; zs(a)^2, zs(b), c. That is, the inputs for the quadratic formula (NOT the solutions, because its part of a code that changes the variables over and over(if that makes sense)).

For the 3rd question; "It is derived from substituting...", my "xs, ys, and zs" are equal to your "x0, y0, z0." What I did here was basically to put the line equations into sphere equation.

Comment to your 4th point:
The R I think I have simply forgot to square in the first lines. ( I changed it later so it shouldn't matter)
I am tracing a ray. This is the next step of the code:

z1 = (-b + sqrt(b^2 - 4*a*c))/(2*a); x1 = Ax*z1+Bx; y1 = Ay*z1+By;
z2 = (-b - sqrt(b^2 - 4*a*c))/(2*a); x2 = Ax*z2+Bx; y2 = Ay*z2+By;

So basically, I just need a set of expressions that does the job for a cylinder instead of a sphere. At least, this is what I'm thinking. I am not sure if this will work.
 
  • #4
Joacim Jacobsen said:
For the first two questions: I got a,b and c from putting the equation for a line into the equation for a sphere. I ended up with a quadratic equation when I solved for "Az". a,b and c are simply; zs(a)^2, zs(b), c. That is, the inputs for the quadratic formula (NOT the solutions, because its part of a code that changes the variables over and over(if that makes sense)).

For the 3rd question; "It is derived from substituting...", my "xs, ys, and zs" are equal to your "x0, y0, z0." What I did here was basically to put the line equations into sphere equation.
It would be helpful to see the equations you used for the line (parametric equations? symmetric equations?, vector equation?) as well as at least some of your work, rather than just a description of what you did.
 
  • #5
This is the equations I used for the line:
x=Ax*z+Bx, y=Ay*z+By (I solved for z)

This is basically the .m-file that make up the intersection(sphere):

function [r1v,a2v] = lens_vec(s1,r1,a1v,r0v,v1,v2,direk,mirror_skew)

%Find intersection and refraction:

% s1 - sphere center (z-value)
% r1 - sphere radius
% a1v - unit vector defining direction of ray
% r0v - starting point of ray
% v1 - speed of sound, material 1
% v2 - speed of sound, material 2
% direk - choose croosing, direk==0 to the right of s1, direk==1, to the

% left of s1
xs = 0.0000; ys=mirror_skew; zs=s1; % center of sphere

R = r1; % radius of sphere

%...Define parameters for x and y coordinate of straight line (Ax,Bx),
%...(Ay, By)

if a1v(1) ~= 0

Ax = a1v(1)/a1v(3);

else

Ax = 0;

end

if a1v(2) ~= 0

Ay = a1v(2)/a1v(3);

else

Ay = 0;

endBx = r0v(1)- Ax*r0v(3);

By = r0v(2)- Ay*r0v(3);

% Intersection straight line and sphere:

a = 1 + Ax^2 + Ay^2;
b = 2*(-zs + Ax*(Bx-xs) + Ay*(By-ys));
c = zs^2 + (Bx-xs)^2 + (By - ys)^2 - R^2;

z1 = (-b + sqrt(b^2 - 4*a*c))/(2*a); x1 = Ax*z1+Bx; y1 = Ay*z1+By;
z2 = (-b - sqrt(b^2 - 4*a*c))/(2*a); x2 = Ax*z2+Bx; y2 = Ay*z2+By;

% (After this comes a section on Snell's law and refraction code)
 

Related to Intersection between line and cylinder

1. What is the equation for the intersection between a line and a cylinder?

The equation for the intersection between a line and a cylinder is determined by setting the equations for the line and the cylinder equal to each other. This results in a quadratic equation, which can be solved to find the coordinates of the points where the line intersects the cylinder.

2. How many points of intersection can a line have with a cylinder?

A line can have zero, one, or two points of intersection with a cylinder. This depends on the orientation of the line and the location of the cylinder in relation to the line. If the line is parallel to the cylinder, there will be no points of intersection. If the line is tangent to the cylinder, there will be one point of intersection. And if the line intersects the cylinder at two different points, there will be two points of intersection.

3. Can a line intersect a cylinder at an infinite number of points?

No, a line can only intersect a cylinder at a maximum of two points. This is because a cylinder is a three-dimensional shape with a finite surface area, so a line can only intersect it at a limited number of points.

4. How can the intersection between a line and a cylinder be used in real life?

The intersection between a line and a cylinder has many practical applications. It can be used in engineering and design to determine the optimal placement of pipes, wires, or other cylindrical objects. It can also be used in computer graphics and animation to create realistic 3D objects and scenes.

5. Are there any special cases where a line and a cylinder do not intersect?

Yes, there are two special cases where a line and a cylinder do not intersect. The first is when the line is parallel to the cylinder, as mentioned earlier. The second is when the line is contained within the cylinder, meaning it lies completely inside the curved surface. In this case, the line and the cylinder do not intersect because they are essentially the same shape.

Similar threads

Replies
13
Views
1K
  • Precalculus Mathematics Homework Help
Replies
3
Views
1K
Replies
2
Views
1K
  • General Math
Replies
4
Views
1K
  • Set Theory, Logic, Probability, Statistics
Replies
11
Views
1K
  • Calculus and Beyond Homework Help
Replies
11
Views
2K
  • STEM Educators and Teaching
2
Replies
36
Views
4K
  • General Math
Replies
8
Views
3K
Back
Top