Hi i’m starting to work with webGL using Three.js and I need to detect if a click on a sphere is within a certain section of it’s surface.
Currently i can detect if the sphere was clicked and get the coords of the point clicked. Now what i need is to detect if that click was in a certain region of that sphere, based on a array of 3D points from that sphere (another suggestion is ok).
The sphere is in the center point, and the point is garrantied to be on the surface of the sphere. Now i need to calculate if it’s just within a section section. Any suggestions? My problem seams to be more mathematical.
Also i prefere a generic way to do this because the sections may be just a triangle or may be more complex figures.
I’ve ended using a different method then the suggestions.
I’m using matrix determinants where: (T1, T2, T3) are points that form a triangle and X is the point i want to know if it’s inside this triangle, then i simple calculate 3 determinants where:
If all determinants are the same sign, then the point is inside the triangle.
Now i form a list of triangles based on the selection area and check if the point is inside one of those triangles.
The function
pointInTriangle(x,t1,t2,t3)does the determinant verification.