# Rotating a 3d-ellipse equation?

So I have very limited Linear Algebra knowledge, and I'm trying to program a computer graphics application in Android using OpenGL.

I understand my design is not great, so if you have questions as to why I did things the way I did, there's only two possible answers: 1) I didn't know what I was doing. 2) It made sense to me at the time and I just chose to do it that way :)

Anyways,

I have a set of points given to me in a file that define an large, complex object in 3d. The centroid of this object is calculated and the object is translated so that the centroid is at the origin. The object is also scaled. These translated/scaled points are stored in an array.

So to recap, I have points that define the object in a FILE. I also have transformed points in my app in an ARRAY.

As my program runs, the user can rotate this object. The rotations are stored in an accumulated rotation matrix, which is multiplied to the points by the OpenGL engine (but not actually changing the array of points). Thus, my points are "unrotated" in my array, but visually, they appear rotated.

Furthermore, in my app, the user moves the center of a sphere onto a point on the object. This point is unrotated, unscaled, and untranslated so that it I can connect it to a point from my original file. (I am sure of the accuracy of this part, I am definitely getting the point I want). I need this transformation from my sphere center point to the actual point in my file because it is an important piece of data for my app.

Now is the tricky part. The user, after moving the sphere to the point, can stretch the sphere into an ellipsoid (but the center remains the same). When they are done, they hit a button and it calculates all the points from my object that are inside the sphere/ellipsoid.

This is where the trouble begins. Initially, my method for solving this was to take my center point (the raw, untranslated/unscaled/unrotated point that was saved earlier), and write the equation of an ellipsoid around it. So:

$$\frac{(x-cx)^2}{a^2} + \frac{(y-cy)^2}{b^2} + \frac{(z-cz)^2}{c^2} = 1$$

where $(cx,cy,cz)$ is the center point. I already have values for a b and c (and those are correct values). I then iterate through all the points of my object's ARRAY, unscale and untranslate them so they become points from the FILE, and plug them into this equation. If the left side of my equation is <= 1, then I save the point.

This works very well, when the user does not rotate the object at all. However, as soon as they start to rotate the object, the calculation isn't correct. I know why this is the problem: I have failed to factor in the rotation to my object array points.

The question I have for you all, is how do I do that? Given that I have:

1. the unscaled/untranslated/unrotated center of my sphere/ellipsoid
2. All of my object's scaled/translated points
3. The accumulated rotation matrix of my object

One thing that would be sweet is if there was a way to rewrite my ellipse equation so that its axes are rotated?

• So we have two kind of objects in two coordinate systems: 1. the ellipsoid in the user coordinate system to be used as query volume for 2. the object points in your original system. Several options seem possible: a) bring the ellipsoid from system 1 to your system 2, or b) your objects points from 2. to the system 1. – mvw Jul 20 '15 at 21:44