Using similar triangles, find l?

44 Views Asked by At

I am attempting to render some 3D shapes and am having trouble with some of the math. I'm hoping someone can help me out here.

Given two arbitrary points in space, P and C, I need to find l. I have L and r. Unfortunately, since I do not know my orientation, it's not as simple as L*r/(P.x - C.x). Is there another way I might go about finding l?

enter image description here

More information:

What I am attempting to do is find the distance from an arbitrary point P in 3D space to the edge of a cylinder (centered at C). P may be anywhere around the cylinder, not necessarily just to the left or right (+/- X axis). The points are given as (x,y,z).

I attempted to calculate the side opposite L (call it X) by finding P.x - C.x. Unfortunately, that did not work.