View Full Version : MEL: MATH: two points = offset into degrees
MasterZ 05092006, 01:55 AM If you takes two points in XYZ coordinates and then gets their offset in XYZ also.
I can convert using the suggested atan2 with rad_to_deg to find Z rotation with X and Y positions. I can find Y rotation with Z and X position. I can even find X rotation with Z and Y position.
It's the combination of Rotations for XYZ position offset that is extremely more challenging.
What's the secret?
Note I don't want to create entities aim etc. it's way to slow.


MasterZ
05092006, 05:28 AM
after wasting all day, I finally came to the conclusion that what is needed is the hypotenuse of the Offsets X+Z as the variable with offsetY in the atan2 with 'rad_to_deg'ree which provides Z rotation with the standard Y rotation in mind. you now have enough to pinpoint a 2 point offset angle in degrees.
To try and explain further... if you rotated back the y axis the x length would be longer due to Pythagorean's Theorem.
goleafsgo
05092006, 01:50 PM
Sorry, but I found that very hard to follow. :)
What exactly are you trying to calculate?
MasterZ
05102006, 06:37 AM
Right sorry wasn't sure if anybody was listening. I suppose I need to explain that a little better but it is confusing stuff.
Basically we are taking aim constraint for the average person, in the land of MEL + MATH we find the center of one object needs to orient to the center of another object, so we want the rotational values for point A to point to point B.
Assuming we find the offset… A becomes zero (0,0,0), B is XYZ.
We know that if you use atan2 or arc tangent command with two values X & Y we get a value returned in radians so we convert to degrees with rad_to_deg. Now we have the Z rotation for pointing to the X and Y. We also have an issue with Z via Y rotation so X & Z similarly give us Y rot. We only need two rotations to point to a point in XYZ, I thought we might need three (and if you are worrying about roll and yaw we might have to consider that via a matrix as briefly touched on in another thread), but I did various things and always had a problem with all three values being none zero.
The solution is to put A^2 = B^2 + C^2 Pythagorean's ideas to work further.
We can imagine if we removed (rolled back to zero) the y rotation we would see that the point is further along X then we previously imagined so calculating it's true distance is related to the square root of the squares added together (of rise and run). Then you’re ready to do the rotations as before.
One more thing I didn't mention before is you should do the rotation of Z first and then apply Y rotation after or it doesn't work right. (The Pointer spins on axis.)
If you’re trying to solve the problem yourself the simple notes above are enough to help anyway.
Why am I here asking this question and working on this you ask? Well it relates to fluids only being scrabbled by the existing fields and not controlled (as one expects), so I am rebuilding that stuff and I need to know if a point for each of potentially millions of voxels are within a given geometry (per frame) [Using Aim Constraints is simply too slow and just not efficient.] Then I can apply forces out and away or in towards the rotational center of the object. To know the closest surface point's normals relative a voxels normal relative the geometry's center is basically I believe what I need at this time to achieve these means, but whatever each to their own methods.
Anyway it’s been said finding if a point is inside and object or not is impossible, but anything is possible. Another way might be to pass a plane through a geometry and count holes or loops and breaks and see where it intersects etc. but I only do that type of thing if morphing from one mesh to another, that would require popping a hole etc.
mhovland
05102006, 01:33 PM
The solution is to put A^2 = B^2 + C^2 Pythagorean's ideas to work further.
Isn't pythagoras a^2+b^2=c^2? Thus, solving for a^2 would be, a^2=c^2b^2, wouldn't it?
Just checking my math :)
goleafsgo
05102006, 01:40 PM
Using Aim Constraints is simply too slow and just not efficient.
You can delete the constraint after you use it. It basically has to do what you are trying to calculate anyways so I don't think you are going to end up saving as much time as you think you are. I could be wrong though...
MasterZ
05302006, 09:41 PM
Isn't pythagoras a^2+b^2=c^2? Thus, solving for a^2 would be, a^2=c^2b^2, wouldn't it?
Just checking my math :)
Lets be clear for sure, thanks for pointing out the typo.
I definitely meant to say the theorem correctly, which is A^2 + B^2 = C^2 but the Letters are meaningless/interchangeable anyway. As long as you take the square root of the sum of the other two squares you get the diagonal length of the other two right angle lengths.
MasterZ
05302006, 09:52 PM
You can delete the constraint after you use it. It basically has to do what you are trying to calculate anyways so I don't think you are going to end up saving as much time as you think you are. I could be wrong though...
Well to do it twice and perform speed tests to find out since I already have the pure math correctly working is not something I have time for. I am pretty sure creating visual displayed objects with node properties etc. is never going to be faster then one or two small functions. It may provide better memory management etc. though. Besides what I am doing with it is taking way more resources then that part so it likely is relatively nominal impact (and a better reason to keep all of it as efficient as possible).
I am aware of ‘clear’ to empty my arrays but I am likely looking at making some (if not all) internal function values global/reusable (as a test) since millions of calls seem to be resulting in memory leaks still. I suppose the system should but might not be garbage collecting or destroying internally created values in functions of MEL script. This might be worth a test, one function creating an internal integer called millions of times should result in not growing mayabatch.exe mem usage?!? I fear something is still leaking even with ‘clear’ to help with arrays[] anyways.
CGTalk Moderation
05302006, 09:52 PM
This thread has been automatically closed as it remained inactive for 12 months. If you wish to continue the discussion, please create a new thread in the appropriate forum.
vBulletin v3.0.5, Copyright ©20002015, Jelsoft Enterprises Ltd.