# I have troubles intersecting two spheres

## Recommended Posts

Hello everybody ! My problem is next - i have two Mesh.Sphere and i want to unite them, cause now the one is above the other. I guess i have to intersect them, so the both spheres will look like one object, but the only method (Mesh.Intersect) i found returns bool and nothing really happens. If its not inconvinient for you, i will be very happy if you post some code with the answer.

##### Share on other sites
Quote:
 Original post by PatzolinoHello everybody !My problem is next - i have two Mesh.Sphere and i want to unite them, cause now the one is above the other. I guess i have to intersect them, so the both spheres will look like one object, but the only method (Mesh.Intersect) i found returns bool and nothing really happens. If its not inconvinient for you, i will be very happy if you post some code with the answer.

Mesh.Intersect probably return rue if the two mesh are intersecting each other. Creating an union (and not an intersection) of two mesh is harder. The simplest solution is to create a mesh that contains the two other meshes, but it should be better to avoid storing parts that are not visible. The correct solution is to ue CSG (constructive solid geometry) to do the job - and that's the hard thing... Here is a PDF presentation about this subject.

HTH,

##### Share on other sites
Thank you very much for the information. I took a look at the pdf file, and unfortunately it wont be very helpful to me since im not so advanced in the DirectX to manage to release the ideas in the pdf in DirectX code. You mentioned that there is a more simply way to do that. Since i dont have many objects in my project, i dont think it will be a big problem to keep the non-seeing sides. Would you help me with releasing this your idea? Thank you very much !!
Best regards, Plamen Dimitrov

##### Share on other sites
Quote:
 Original post by PatzolinoThank you very much for the information. I took a look at the pdf file, and unfortunately it wont be very helpful to me since im not so advanced in the DirectX to manage to release the ideas in the pdf in DirectX code. You mentioned that there is a more simply way to do that. Since i dont have many objects in my project, i dont think it will be a big problem to keep the non-seeing sides. Would you help me with releasing this your idea? Thank you very much !!Best regards, Plamen Dimitrov

To create a simple union of two meshes, you'll have to read the informations of a mesh and add these informations to the other mesh. For example, consider a very simple mesh with a single triangle and - of course - 3 points. You want to 'unite' this mesh with a similar one.
mesh A;mesh B;int vcount = B.get_vertice_count();for each vertex V in A  add V in B// T(a,b,c) is a triangle that uses vertices a,b,c in the vertice listfor each triangle T(a,b,c) in A  create a triangle T'(a+vcount,b+vcount,c+vcount)  add T' to B

It seems you are csharping, and I don't know much about this language. I hope the pseudo-code above will help you. Of course, the DX SDK may be more complex (the mesh SDK deals with mesh parts and so on) but you get the idea.

Regards,

## Create an account

Register a new account

• ### Forum Statistics

• Total Topics
627716
• Total Posts
2978783

• 9
• 21
• 14
• 12
• 42