If you using aim/point constraints in Maya, you are not using a combination of Vector and Trigonometry calculations under the hood the software does for you. Using Vector math directly can allow you to work not only smarter but also faster and easier, once you get hang of it.
If you aim to do some calculation using Vector math in Python, scripting to get a value is probably the fastest way. However, if you want to implement Vector math into your Rig, we can use do the same calculations using Nodes (Expressions would be another alternative, but I avoid using those).
This post discusses using OpenMaya MVectors class.
# Creating MVectors in Maya
import pymel.core as pm
import maya.api.OpenMaya as om
import math
obj1, obj2 = pm.PyNode('locator1'), pm.PyNode('locator2')
obj1.t.set(2,2,2)
v1, v2 = om.MVector(obj1.t.get()), om.MVector(obj2.t.get()
# Length
Uses - Distance Between two Pointsom.MVector(v2-v1).length()
# Normalize
The Vector direction at a length of one. This normalizes the Vectors,Uses - make comparisons based on direction only.
om.MVector(v2-v1).normal()
# DOT Product / Angle Between Two Vectors
The Dot product multiplies two vectors and returns a Scalar number (no Vector).If we normalize one Vector, returns a number between 0 and 1
> very useful to calculate Angles between Vectors, see if they face the same direction, etc
> find out what angle something is pointing
dot = v1*v2 # returns degreee in radiants dot = v1*v2.normal() # returns value between 0 and 1, 0=parallel print om.MAngle(math.acos(dot)).asDegrees() # returns the degree
Source and Resources:
http://www.naughtynathan.co.uk/?p=296
Short overview of MVector operations
No comments:
Post a Comment