What you're describing should work perfectly, Anthony, however, there's
one optimization -- Vector A is already on the plane defined by normal C
based on the constraints Sam gave, so we really (using your numbers)
only need to find B', and then the angleBetween(A, B'). For the actual
3D math, and allowing normal C to be an arbitrary vector, I'd do
something like this:
A = Current Vector
B = Desired Direction Vector
C = Normalize(Desired Normal axis)
tangent = Normalize(A Cross C)
# Probably unnecessary, but a valid step just to check. Find the
"Correct" A' based on the normal and tangent :)
A' = C Cross tangent
A' = Normalize(A')
# Ok, now we have a proper A' that is perpendicular to the normal and
the tangent, and normalized
# Project the B onto the plane defined by A' and tangent
B'x = Dot(A', B)
B'y = Dot(tangent, B)
B' = (A' * B'x) + (tangent * B'y)
angleBetween(A', B')
# If you want to take this one more step and find the final vector A,
it's pretty simple at this point, even without the angleBetween.
# Just normalize B' and multiply by A's original length
FinalA = Normalize(B') * A.Length
On 11/3/2014 8:57 PM, Anthony Tan wrote:
It does, but you're not giving many constraints so you'll have to deal
with the general case. Since your three vectors have no actual
relationship between them, and if i understand correctly that the axis
of rotation is the major constraint, you need to wrangle them like this:
A' = Project A onto plane defined by normal C
B' = Project B onto plane defined by normal C
and then angleBetween (A', B')
If A' == A, but B' != B or vice versa, you can't get a clean solve
since you're either trying rotate on a plane that doesn't contain B
(A==A, but B' != B) or your source vector doesn't lie on the correct
starting plane (A' != A). Either way you need to crunch your source
and target vectors down so it becomes a straightforward angle problem.
Does that help any? I'm mangling some data (well, building a mesh)
right now but in my head this is how I'd attack the problem. If my 3D
maths isn't too rusty, i haven't forgotten anything.
On Tue, Nov 4, 2014, at 02:01 AM, sam williams wrote:
the 'angleBetween' gives you the angle you should rotate vector 1
to so that it aligns perfectly with vector 2. In my example
vector 1 can only partially point in the direction of vector 2
because its only allowed to rotate around a specific axis (in my
example (0,1,0))
see it like vector 1 is the metal arm on a compass and vector 2 is
magnetically pulling it in its direction. But obviously the compass
arm cannot leave its axis, but it still points in the direction of
vector 2 as much as it can within its circle of rotation. The other
vector maybe pointing anywhere. I just need a formula that will
calculate how many degrees the compass arm needs to rotate to be
pointing at vector 2 (within its axis).
does this make more sense?
Sam
--
You received this message because you are subscribed to the Google
Groups "Python Programming for Autodesk Maya" group.
To unsubscribe from this group and stop receiving emails from it, send
an email to [email protected]
<mailto:[email protected]>.
To view this discussion on the web visit
https://groups.google.com/d/msgid/python_inside_maya/1415077031.2874332.186751973.40B0D4DC%40webmail.messagingengine.com
<https://groups.google.com/d/msgid/python_inside_maya/1415077031.2874332.186751973.40B0D4DC%40webmail.messagingengine.com?utm_medium=email&utm_source=footer>.
For more options, visit https://groups.google.com/d/optout.
---
This email is free from viruses and malware because avast! Antivirus protection
is active.
http://www.avast.com
--
You received this message because you are subscribed to the Google Groups "Python
Programming for Autodesk Maya" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/python_inside_maya/545A4678.8090501%40gmail.com.
For more options, visit https://groups.google.com/d/optout.