brohan322
brohan322

Reputation: 368

How to find points that lie inside a 3D boundary

I'm currently working on a project in Android that is Java-based. I am using OpenGL-ES 3.0.

In my project, I have a large, complex 3D object (a human head) with 100000+ vertices and 400000+ triangles. The object's vertices are stored in an array. The object can be rotated relative to its centroid.

I am trying to implement a function where the user selects a set of points on the head, and a line is drawn connecting each point (kind of like "connecting the dots"). In other words, the user selects points on the head (p1, p2, p3...pn), and the chosen points will change color. Then, after choosing the last point (pn), an algorithm runs to calculate all the vertices that lie between each point (for example, p1 and p2). Those vertices will then change color, so the user sees a line (or close to a line) between each point they chose.

I have already implemented a way of allowing the user to select the points, and see those points by changing their colors. The difficulty I am having is the implementation of the lines in between the points.

The only idea I currently have to draw these lines is to make use of code I have already programmed. I have code that allows the user to move a ellipsoid (they can choose the dimensions and rotate the ellipsoid). They move the ellipsoid to a location on the head and run an algorithm that calculates all of the points of the head that lie inside the volume of the ellipsoid, and changes those points' colors.

My idea was to take the midpoint of p1 and p2, set that as the center of the ellipsoid, and rotate/stretch the ellipsoid dimensions so that one axis runs from p1 to p2 and the other one is some large value. Basically, it would look like taking a flattened ball-like shape (something like a red blood cell) and putting one end of the ball on p1, and the opposite end on p2. I could then run the algorithm that I already coded to find all the points inside that ellipsoid. Then I can change the color of these points and the user can see a line between each point they selected.

Does anyone have any criticisms of this technique? Are there other ways I could possibly achieve the result I desire?

Upvotes: 1

Views: 294

Answers (1)

Aiman Al-Eryani
Aiman Al-Eryani

Reputation: 709

To check if a point touches or is inside an ellipsoid:

  • Translate the world by -x, -y, -z (x, y and z being the ellipse's center) such that (0, 0, 0) becomes the ellipsoid's new center.
  • Rotate the world so that the ellipsoid makes 0 degrees.
  • Scale the world by 1/a, 1/b, and 1/c (a, b and c being the length 3 elliptical axes).
  • if sqroot(a^2 + b^2 + c^2) <= 1, then the point lies inside the sphere.

Upvotes: 1

Related Questions