- #1

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

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: