Created
August 13, 2015 22:18
-
-
Save JokerMartini/c963ae5954268f7e62ea to your computer and use it in GitHub Desktop.
Maxscript: This snippet demonstrates how to calculate the corner point for a right angle when knowing 2 points and a normal.
This file contains hidden or 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
fn GetVectorsAngle v1 v2 = | |
( | |
theAngle = acos(dot (normalize v1) (normalize v2)) | |
) | |
fn PlaceAlongVector pos:[0,0,0] vec:[0,0,1] offset:0 = | |
( | |
pos + (normalize (vec)) * offset | |
) | |
/* Test Scene Setup */ | |
clearlistener() | |
format "\n" | |
delete objects | |
pln = plane width:5 length:5 pos:[0,10,10] wirecolor:yellow | |
rotate pln (angleaxis 30 [1,0,0]) | |
s1 = sphere pos:[0,30,0] wirecolor:red radius:2 | |
center = pln.pos | |
normal = pln.transform.row3 | |
/* Find the length to create a right traingle */ | |
-- get angle difference between 2 vectors | |
difVector = s1.pos - pln.pos-- vector between plane and ball | |
objVector = pln.transform.row3 -- vector using normal of plane | |
dist = distance pln.pos s1.pos | |
calcAng = GetVectorsAngle difVector objVector | |
-- calculate the length of side to create a right angle | |
len = cos(calcAng) * dist | |
-- place point which would create a rightAngle at the sphere | |
cornerPos = PlaceAlongVector pos:pln.pos vec:objVector offset:len | |
point pos:cornerPos size:2 wirecolor:yellow |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I'd rather keep getting the point-line projection simple, i.e.
where pln.dir is (obviously) a unit vector.