# Two meshes intersection

Hi guys
I have a sphere (Earth) and a cone intersecting with it. What is the best way to draw the projection of this cone onto the surface of the sphere? Use raycaster or stencil buffer mb?

Thanks in advance.

Tricky one. It looks like you have multiple satellite projections too so that pretty much rules out doing it in the Earth fragment shader.

What about changing the vertex positions on the cone end-cap, perhaps if the cone end cap was a separate surface you could reverse the normals. Given it’s a sphere I don’t think I’d use a raycast, but rather just calculate where the vertex positions need to be. Can’t say off the top of my head in the time I have available exactly what the maths would be, I’d have to sit down with it, but I think that’s the approach that sounds easiest to me.

2 Likes

Looks like functionality of a spot light with certain angle of its cone and negated penumbra value in fragment shader, when basically there is no light in the center, but it increases, getting further from the axis of the light cone.

I know the raycaster would work.
In this screen grab I raycasted a grid onto the model

1 Like

This is similar

2 Likes

Just a small “hack” of SpotLight

``````float spotEffect = 1. - smoothstep( spotLight.coneCos, spotLight.penumbraCos, angleCos );
spotEffect = pow(spotEffect, 32.);
``````

Original line

I inverted the value of `spotEffect` (that is based on `penumbra` property) by subtracting its value from `1.`, and called `pow()` to make that “ring” more narrow.

3 Likes

Thanks for idea! Need to think about it

I like this solution)) but it’s not exactly what I need. I need the base of the cone to be displayed as a grid (or just a circle, without higlighting) on sphere surface and in places where several cones overlaping, their bases must be layered on top of each other

So I’m wrong with what “projection” is
As:

The most enigmatic part is “displayed as a grid”. Any explanatory/reference picture?

Then it may be useful to calculate the intersection lines. I did something similar with sphere and cylinder and cylinder with cylinder.

Inner Geometry (Triangulation)
See e.g. InnerGeometryTHREEi_01
Is some mathematics.

I only found something in German, but the formulas are clear and the little text easily translatable.

Schnitte von Kugel, Zylinder und Kegel – GeoGebra

1 Like

Something like these hemispheres, but as circles on the surface. Anyway, it can be solid circles, wich can overlap each other)

@Korvin007
Then you need an approach with projection, that @hofk mentioned before.
Something like this (I’ve modified the original example from @sciecode (btw, haven’t seen him for long time already, hope he’s okay ), adding that polar grid of aqua color): http://jsfiddle.net/prisoner849/6vjth7nw/

1 Like

Seems to be what I need! Thanks a lot for your help!

But you also need to take normals in count, to prevent projection to get through a mesh.