Last active
October 13, 2017 09:03
-
-
Save TSCG/70f8240d46ca07ec19ad to your computer and use it in GitHub Desktop.
GetNearestPointToLine / Maya
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#pointAとpointBを結ぶ直線とpointPの最近点の座標を返す | |
import pymel.core as pm | |
import pymel.core.datatypes as dt | |
import maya.cmds as cmds | |
def GetNearestPointToLine(pointA,pointB,pointP): | |
AP = pointP - pointA | |
nAB = (pointB - pointA).normal() | |
dist_AX = dt.dot( nAB, AP ) | |
pointRet = dt.Vector(0, 0, 0) | |
pointRet.x = pointA.x + ( nAB.x * dist_AX ) | |
pointRet.y = pointA.y + ( nAB.y * dist_AX ) | |
pointRet.z = pointA.z + ( nAB.z * dist_AX ) | |
return pointRet | |
#usage | |
#select = cmds.ls(sl=True, fl=True) | |
#pointA = pm.PyNode(select[0]).getTranslation('world') | |
#pointB = pm.PyNode(select[1]).getTranslation('world') | |
#pointP = pm.PyNode(select[2]).getTranslation('world') | |
#NP = GetNearestPointToLine(pointA,pointB,pointP) | |
#cmds.spaceLocator( p=NP ) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment