Created
July 29, 2015 14:39
-
-
Save JokerMartini/12be5ca9bb988aecfbd7 to your computer and use it in GitHub Desktop.
Maxscript: This example demonstrates how to calculate the offset for a corner point. It allows users to define how far to offset the new point from it's original location.
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
/* Test Scene Setup */ | |
clearlistener() | |
delete objects | |
/* generate an array of random points */ | |
randomPts = for i = 1 to 3 collect (random [-30,-30,0] [30,30,0]) | |
/* Requires 3 point3 values */ | |
fn CalculateOffset offset:8 ptA:undefined ptB:undefined ptC:undefined = | |
( | |
BA = ptB-ptA | |
BC = ptB-ptC | |
ang = acos(dot (normalize BA) (normalize BC) ) | |
vec = normalize(normalize(BA) + normalize(BC)) | |
P1 = vec * offset + ptB | |
) | |
fn GenerateOffset pts:#() = | |
( | |
a = CalculateOffset ptA:pts[1] ptB:pts[2] ptC:pts[3] | |
b = CalculateOffset ptA:pts[3] ptB:pts[1] ptC:pts[2] | |
c = CalculateOffset ptA:pts[2] ptB:pts[3] ptC:pts[1] | |
/* spline showing original positions */ | |
sp = splineShape wirecolor:yellow | |
addNewSpline sp | |
addKnot sp 1 #corner #line pts[1] | |
addKnot sp 1 #corner #line pts[2] | |
addKnot sp 1 #corner #line pts[3] | |
close sp 1 | |
updateShape sp | |
/* offset points */ | |
point pos:a wirecolor:green size:2 | |
point pos:b wirecolor:green size:2 | |
point pos:c wirecolor:green size:2 | |
) | |
GenerateOffset pts:randomPts |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment