CGTalk > Software > Autodesk 3ds max > 3dsMax SDK and MaxScript
Login register
reply share thread « Previous Thread | Next Thread »
 
Thread Tools Search this Thread Display Modes
Old 04-18-2007, 09:52 AM   #31
rdg
random data generator
 
rdg's Avatar
portfolio
Georg Duemlein
New Zealand
 
Join Date: Feb 2004
Posts: 779
Send a message via AIM to rdg
easing equaotations

this is a maxscript version of Robert Penners Easing Equotations for Flash:

Code:
struct rpEFn ( -- --- -- Easing Equotations by Robert Penner -- http://www.robertpenner.com/ -- The BSD License: http://www.opensource.org/licenses/bsd-license.php -- --- -- maxScript port by Georg Duemlein -- 2007-04-18 -- http://www.preset.de -- --- -- previews: http://www.gizma.com/easing/ -- --- -- t: current time -- b: start value -- c: end value -- d: duration -- --- -- simple linear tweening - no easing, no acceleration fn linearTween t b c d = ( c*t/d + b ), -- quadratic easing in - accelerating from zero velocity fn easeInQuad t b c d = ( t /= d c*t*t + b ), -- quadratic easing out - decelerating to zero velocity fn easeOutQuad t b c d = ( t /= d -c * t * (t-2) + b ), -- quadratic easing in/out - acceleration until halfway, then deceleration fn easeInOutQuad t b c d = ( t /= d/2 if (t < 1) then ( c / 2 * t * t + b )else( t-=1 -c / 2 * (t* (t - 2) - 1) + b ) ), -- cubic easing in - accelerating from zero velocity fn easeInCubic t b c d = ( t /= d c*t*t*t + b ), -- cubic easing out - decelerating to zero velocity fn easeOutCubic t b c d = ( t /= d t-=1 c*(t*t*t + 1) + b ), -- cubic easing in/out - acceleration until halfway, then deceleration fn easeInOutCubic t b c d = ( t /= d/2 if (t < 1) then ( c/2*t*t*t + b )else( t -= 2 c/2*(t*t*t + 2) + b ) ), -- quartic easing in - accelerating from zero velocity fn easeInQuart t b c d = ( t /= d c*t*t*t*t + b ), -- quartic easing out - decelerating to zero velocity fn easeOutQuart t b c d = ( t /= d t -= 1 -c * (t*t*t*t - 1) + b ), -- quartic easing in/out - acceleration until halfway, then deceleration fn easeInOutQuart t b c d = ( t /= d/2 if (t < 1) then( c/2*t*t*t*t + b )else( t -= 2 -c/2 * (t*t*t*t - 2) + b ) ), -- quintic easing in - accelerating from zero velocity fn easeInQuint t b c d = ( t /= d c*t*t*t*t*t + b ), -- quintic easing out - decelerating to zero velocity fn easeOutQuint t b c d = ( t /= d t -= 1 c*(t*t*t*t*t + 1) + b ), -- quintic easing in/out - acceleration until halfway, then deceleration fn easeInOutQuint t b c d = ( t /= d/2 if (t < 1) then ( c/2*t*t*t*t*t + b )else( t -= 2 c/2*(t*t*t*t*t + 2) + b ) ), -- sinusoidal easing in - accelerating from zero velocity fn easeInSine t b c d = ( -c * cos (t/d * (180 / 2)) + c + b ), -- sinusoidal easing out - decelerating to zero velocity fn easeOutSine t b c d = ( c * sin (t/d * 90) + b ), -- sinusoidal easing in/out - accelerating until halfway, then decelerating fn easeInOutSine t b c d = ( -c/2 * (cos(180 * t/d) - 1) + b ), -- exponential easing in - accelerating from zero velocity fn easeInExpo t b c d = ( c * pow 2 (10 * (t/d - 1)) + b ), -- exponential easing out - decelerating to zero velocity fn easeOutExpo t b c d = ( c * (-pow 2 (-10 * t/d) + 1 ) + b ), -- exponential easing in/out - accelerating until halfway, then decelerating fn easeInOutExpo t b c d = ( t /= d/2 if (t < 1) then ( c / 2 * pow 2 (10. * (t - 1)) + b )else( t -= 1 c / 2 * (-pow 2 (-10. * t) + 2 ) + b ) ), -- circular easing in - accelerating from zero velocity fn easeInCirc t b c d = ( t /= d -c * (sqrt(1 - t*t) - 1) + b ), -- circular easing out - decelerating to zero velocity fn easeOutCirc t b c d = ( t /= d t -= 1 c * sqrt(1 - t*t) + b ), -- circular easing in/out - acceleration until halfway, then deceleration fn easeInOutCirc t b c d = ( t /= d/2 if (t < 1) then ( -c/2. * (sqrt(1. - t*t) - 1.) + b )else( t -= 2 c/2. * (sqrt(1. - t*t) + 1.) + b ) ) ) -- sample d = 50. t = 0. while t < d do ( v1 = v2 = v3 = 0 v1 = rpEFn.linearTween t 0. 100. d v2 = rpEFn.easeInOutQuad t 1. 100. d v3 = rpEFn.easeInOutQuad t 0. 1. (d/2) sp = sphere pos:[v1, 0, v2] radius:(.5 + v3) sp.wirecolor = [255,255,255] * v3 -- --- t += .5 max zoomext sel all )


maybe this is usefull for somebody

http://www.robertpenner.com/
http://www.gizma.com/easing/

2007-05-08
I found this API documentation:
http://livedocs.adobe.com/flash/9.0...ng/Elastic.html
and c is the "total change in the animation property".

I also recomend the " Tweening chapter of my book" at Robert Penners site.
I just started reading it and it explains a lot.

Georg
__________________
Georg Duemlein

Last edited by rdg : 05-08-2007 at 04:33 PM.
 
Old 09-04-2007, 11:22 AM   #32
pix3l
New Member
student
 
Join Date: Aug 2002
Posts: 25
Send a message via MSN to pix3l
Angle between points....

Hey people, lovely math here heheh i'v forgotten most of it heheh.
I'm trying now to get the angle between 2 points.

So i looked in the reference. there it says the following :
to calculate the angle use the following formula :
theAngle = acos(dot (normalize v1) (normalize v2))

So i tried this in max. if i select 0.0.0 and 150.661,150.661,0 i get 45. till now all okey.
But if i select 10,10,0 and 150.661,150.661,0 i get 0.0197823

Hmmmmm why?
for both two the angle should be 45. but i get different results.
Any1 who can shed some light on this ?


Many thx in advance!


__________________
-----------------------
http://www.evermotion.org
http://www.pixelstudio.nl
 
Old 09-04-2007, 07:17 PM   #33
xissburg
Frequenter
 
xissburg's Avatar
portfolio
xiss burg
2D/3D Artist, Programmer
Santo Andre, Brazil
 
Join Date: May 2005
Posts: 205
Send a message via MSN to xissburg
Very strange to get 0.0197823, you should get 0 since the vectors are pointing in the same direction(the angle between them is 0 ). Maybe its a float point accuracy problem at the normalization(1 inversion, 3 multiplies and one square root) and the acos. But anyway, the formula is correct.
 
Old 09-04-2007, 11:51 PM   #34
magicm
Maxscript Generator
 
magicm's Avatar
CGSociety Member
portfolio
Martijn van Herk
VFX Technical Director
Freelance
Rotterdam, Netherlands
 
Join Date: Jun 2002
Posts: 1,139
Quote:
Originally Posted by pix3l
So i tried this in max. if i select 0.0.0 and 150.661,150.661,0 i get 45. till now all okey.
But if i select 10,10,0 and 150.661,150.661,0 i get 0.0197823

Hmmmmm why?

The normalize function returns a unit vector, meaning that it's length equals 1 unit. Normalizing [0,0,0] will return [1,0,0], so this explains why the result of your first example is 45. Your second example should return 0, but returns 0.0197823 instead because of round-off errors.

Code:
1. [0,0,0] [150.661,150.661,0] == [1,0,0] [0.707107,0.707107,0] (normalized) == 45 2. [10,10,0] [150.661,150.661,0] == [0.707107,0.707107,0] [0.707107,0.707107,0] (normalized) == 0

Hope this helps,
Martijn
 
Old 09-28-2007, 10:24 AM   #35
Guimas
New Member
Guilherme
London, United Kingdom
 
Join Date: Mar 2007
Posts: 26
Point Inside a 3D topological space

Nice thread!

Any idea in how to test if a point is inside a n-dimensional polyhedron just by coordinates? If one has all the vertexes coordinates of a 3d solid and a point3, how to check if the point3 is inside?

cheers

Last edited by Guimas : 09-28-2007 at 11:57 AM.
 
Old 09-30-2007, 03:57 PM   #36
prettyPixel
Know-it-All
cg artist
 
Join Date: Feb 2005
Posts: 302
I don't have the complete solution but some ideas:

First try a fast test : find if the point is completely outside the volume by using the distance.
For example: you find the center of the bounding box of the volume and the point which is farthest. If your point is farther then it is not inside the volume. It's obvious but that avoid to apply a complex function each time...

After... I'm not sure that is 100% secure but if you use the normal of the faces I think we can have a good approach to do that.
For a convex volume, a point is inside a volume if this point is behind of each face of the volume.
For each face:
+ find the vector of the point-plane projection of the face
+ calculate if the vector have the same direction than the normal of the face
+ if all vectors have the same direction then your point is inside the convex volume

The problem appears when you have a non-convex volume.
For example imagine a form like a "U" (in 3D)
If your point is at the center of the U, ok that does work because the point is really outside the volume in itself.
... but if the point is inside of the volume then there are several faces where the normal is in opposite direction of the vector of the point-plane projection.

Probably the solution is to divide the concave volume in several convex volumes. After you test for each convex volume if the point is inside or not and you stop as soon as you find a point inside...
 
Old 10-01-2007, 07:19 AM   #37
prettyPixel
Know-it-All
cg artist
 
Join Date: Feb 2005
Posts: 302
I had another idea.
If the point is inside the volume, you can trace a ray to any direction and you intersect a face.
You compare the 2 vectors (your ray and the face normal) and if the sign of the dot product is positive then your point is inside the volume. And that could work for a concave volume
 
Old 02-11-2008, 05:56 PM   #38
nenalata
New Member
minns
penryn, United Kingdom
 
Join Date: Feb 2008
Posts: 3
curved lines

hello,
nice one with the geometry, and thanks for starting such a thread,does anyone know how to find the intersection of a plane(or a cube, or polyhedra) and a spline?
 
Old 02-16-2008, 11:19 AM   #39
arketip
Frequenter
 
arketip's Avatar
arketip
Bruxelles, Belgium
 
Join Date: Nov 2005
Posts: 109
Hello,

I had sent a question rather similar about splines but it seems that it is not possible to find a mathematical solution for a spline and the only solution is to convert your spline into on a certain number of lines or walking the spline with iterations.

Here is the thread:
http://forums.cgsociety.org/showthr...89&page=5&pp=15

But if somebody can confirm this...
 
Old 02-16-2008, 11:46 AM   #40
marktsang
Articulator!!!
 
marktsang's Avatar
portfolio
Mark Tsang
Runner/Tealady/B*tch
London, United Kingdom
 
Join Date: Apr 2004
Posts: 1,260
hi arketip,
i also looked for the same thing for a long time -
as you say the only thing i found was subdividing by n interations and getting closest to one of these

i dont think you can do any other way
__________________
Morph Controls Script
*NEW Website*
comming soon!!!



 
Old 02-16-2008, 04:25 PM   #41
arketip
Frequenter
 
arketip's Avatar
arketip
Bruxelles, Belgium
 
Join Date: Nov 2005
Posts: 109
triangle intersection

I have another question.
In this thread there is a solution for finding the intersection between a plane and a line. But do you know what is the best calculation for triangle intersection ?
I can calculate the intersection of the triangle plane and after calculate if this point is inside the triangle. I would like to find an optimized solution. Maybe with the dot product ?
 
Old 02-18-2008, 11:07 PM   #42
nenalata
New Member
minns
penryn, United Kingdom
 
Join Date: Feb 2008
Posts: 3
link

try this , arketip, if you can understand it, which i dont entirely



http://local.wasp.uwa.edu.au/~pbour...etry/linefacet/
 
Old 03-29-2008, 08:34 PM   #43
Anubis
Veteran
 
Anubis's Avatar
Christopher Evans
Art Technical Director
Crytek
Frankfurt am Main, Germany
 
Join Date: Feb 2002
Posts: 174
Is this correct for the intersection of three planes? I have found some situations where it does not seem to return the proper result (not when parallel)

Code:
fn threePlaneInter p1 p2 p3 selectPlanes: = ( local d1 = (dot p1.dir p1.pos ) local d2 = (dot p2.dir p2.pos ) local d3 = (dot p3.dir p3.pos ) local num = ((d1 * (cross p2.dir p3.dir)) + (d2 * (cross p3.dir p1.dir)) + (d3 * (cross p1.dir p2.dir))) local denom = (dot p1.dir (cross p2.dir p3.dir)) print ("num " + num as string) print ("denom " + denom as string) if (abs denom) < 0.0001 then (return undefined) if selectPlanes == true then ( selectMe = #(p1,p2,p3) select selectMe ) return (num / denom) )
__________________
Christopher Evans

Last edited by Anubis : 03-30-2008 at 07:44 PM.
 
Old 04-08-2008, 11:17 AM   #44
Kameleon
Expert
 
Kameleon's Avatar
portfolio
Artur Leao
Co-Founder / Project Manager
You can do it! VFX
Porto, Portugal
 
Join Date: Sep 2004
Posts: 1,030
Here's a function for finding the circumcenter of any given triangle.

Code:
fn f_circumcenter p1 p2 p3 = ( dp1=[0,0,0] dp1.x=(p2.x-p1.x) dp1.y=(p2.y-p1.y) dp1.z=(p2.z-p1.z) dp2=[0,0,0] dp2.x=(p3.x-p1.x) dp2.y=(p3.y-p1.y) dp2.z=(p3.z-p1.z) tnx = dp1.y * dp2.z - dp2.y * dp1.z tny = dp1.z * dp2.x - dp2.z * dp1.x tnz = dp1.x * dp2.y - dp2.x * dp1.y sp1=[0,0,0] sp1.x=(p1.x+p3.x)/2.0 sp1.y=(p1.y+p3.y)/2.0 sp1.z=(p1.z+p3.z)/2.0 dp1.x=(sp1.x-p1.x) dp1.y=(sp1.y-p1.y) dp1.z=(sp1.z-p1.z) dp2.x=tnx dp2.y=tny dp2.z=tnz nx = dp1.y * dp2.z - dp2.y * dp1.z ny = dp1.z * dp2.x - dp2.z * dp1.x nz = dp1.x * dp2.y - dp2.x * dp1.y sp2=[0,0,0] sp2.x=sp1.x+nx sp2.y=sp1.y+ny sp2.z=sp1.z+nz sp3=[0,0,0] sp3.x=(p1.x+p2.x)/2.0 sp3.y=(p1.y+p2.y)/2.0 sp3.z=(p1.z+p2.z)/2.0 dp1.x=(sp3.x-p1.x) dp1.y=(sp3.y-p1.y) dp1.z=(sp3.z-p1.z) dp2.x=tnx dp2.y=tny dp2.z=tnz nx = dp1.y * dp2.z - dp2.y * dp1.z ny = dp1.z * dp2.x - dp2.z * dp1.x nz = dp1.x * dp2.y - dp2.x * dp1.y sx4=sp3.x+nx sy4=sp3.y+ny sz4=sp3.z+nz ax=sp2.x-sp1.x ay=sp2.y-sp1.y az=sp2.z-sp1.z bx=sx4-sp3.x byy=sy4-sp3.y bz=sz4-sp3.z cx=sp3.x-sp1.x cy=sp3.y-sp1.y cz=sp3.z-sp1.z qp1=[0,0,0] qp1.x = cy * bz - byy * cz qp1.y = cz * bx - bz * cx qp1.z = cx * byy - bx * cy qp2=[0,0,0] qp2.x = ay * bz - byy * az qp2.y = az * bx - bz * ax qp2.z = ax * byy - bx * ay dotp=qp1.x*qp2.x+qp1.y*qp2.y+qp1.z*qp2.z lee=qp2.x*qp2.x+qp2.y*qp2.y+qp2.z*qp2.z lee=sqrt lee si=dotp/(lee * lee) circumcenter=[0,0,0] circumcenter.x=sp1.x+ax*si circumcenter.y=sp1.y+ay*si circumcenter.z=sp1.z+az*si return circumcenter )
__________________
Artur Leao | Co-Founder / Project Manager
You can do it! VFX
Porto/Lisbon - Portugal
http://www.ycdivfx.com
 
Old 04-22-2008, 09:37 PM   #45
arketip
Frequenter
 
arketip's Avatar
arketip
Bruxelles, Belgium
 
Join Date: Nov 2005
Posts: 109
Plane-Plane Intersection

Quote:
Originally Posted by PrettyPixel
I think that it is not the easiest solution. If you know a better means...


Here is an improvment of the function for calculating the intersection of 2 planes:

pA, nA : first plane, where p is a point and n is the normal of the plane
pB, nB : the second plane
Code:
fn PlanePlaneIntersection pA nA pB nB = ( dir= cross nA nB perp= cross nA dir p= pA + (dot (pB-pA) nB) * perp / (dot perp nB) ray p (normalize dir) )


This is not checked in the code but if dir=[0,0,0] then the Planes are parallel...
 
reply share thread



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
CGSociety
Society of Digital Artists
www.cgsociety.org

Powered by vBulletin
Copyright 2000 - 2006,
Jelsoft Enterprises Ltd.
Minimize Ads
Forum Jump
Miscellaneous

All times are GMT. The time now is 07:05 PM.


Powered by vBulletin
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.