CGTalk > Software > Autodesk 3ds max > 3dsMax SDK and MaxScript
Login register
Thread Closed share thread « Previous Thread | Next Thread »
 
Thread Tools Search this Thread Display Modes
Old 04-24-2013, 03:45 PM   #1
JokerMartini
Expert
 
JokerMartini's Avatar
portfolio
John Martini
CG Supervisor, 3D, Maxscript, VFX
Ingenuity Engine
Los Angeles, USA
 
Join Date: Mar 2009
Posts: 1,299
Send a message via AIM to JokerMartini
Matching Axis from Position points

So what I'm trying to do is take an array containing X number of point3 values (no less then 3 points) and create teapot at the center location of those points. Then from there align the teapot so it's Y axis is pointing at the first item in that point3 array and the Z axis is point outward from those points (like a local axis)
The image on the left is what I have so far. The item on the right in the image is what I'm after. Hope someone can help.
Thank you

Starter code is below for testing.



Code:
( delete objects local columns = 6 local columnAngle = 360.0 / columns local radius = (units.decodevalue "20.0cm") local master = point pos:[0,0,0] local ptsArr = #() local posArr = #() for c = 1 to columns do ( calcX = radius * cos((c-1) * columnAngle) calcY = radius * sin((c-1) * columnAngle) pos = [calcX,calcY,40] pt = text text:(c as string) pos:pos size:5 wirecolor:green parent:master append ptsArr pt ) rotate master (AngleAxis (random -360 360) [1,1,1]) delete master posArr = for p in ptsArr collect p.pos --place point at the center point of the position points centerPos = [0,0,0] for o in posArr do centerPos += o centerPos/=posArr.count --the Y axis should point at the first item in the array -- the Z axis should point along the normal newPoint = point pos:centerPos size:radius wirecolor:yellow cross:false box:false axisTripod:true )
__________________
____________ ___ __ _
John A. Martini
JokerMartini@hotmail.com
www.JokerMartini.com
 
Old 04-24-2013, 04:40 PM   #2
denisT
MAX Doctor
 
denisT's Avatar
portfolio
Denis Trofimov
CA, USA
 
Join Date: Jul 2009
Posts: 9,308
Send a message via ICQ to denisT
are all points at the same plane? are they flatten?
 
Old 04-24-2013, 05:35 PM   #3
JokerMartini
Expert
 
JokerMartini's Avatar
portfolio
John Martini
CG Supervisor, 3D, Maxscript, VFX
Ingenuity Engine
Los Angeles, USA
 
Join Date: Mar 2009
Posts: 1,299
Send a message via AIM to JokerMartini
yes they are all flat and on the same plane Denis.
__________________
____________ ___ __ _
John A. Martini
JokerMartini@hotmail.com
www.JokerMartini.com
 
Old 04-24-2013, 05:55 PM   #4
denisT
MAX Doctor
 
denisT's Avatar
portfolio
Denis Trofimov
CA, USA
 
Join Date: Jul 2009
Posts: 9,308
Send a message via ICQ to denisT
Quote:
Originally Posted by JokerMartini
they are all flat and on the same plane

so we need at least two vectors to make a matrix.
one vector is from center to the first point
second could be from center to second point...
in this case the matrix is:
Code:
fn multipointTM points = if points.count > 1 do ( center = [0,0,0] for p in points do center += p.pos center /= points.count front = normalize (points[1].pos - center) side = normalize (points[2].pos - center) up = normalize (cross front side) -- orthogonalized up side = normalize (cross up front) -- orthogonalized side tm = matrix3 front side up center ) delete objects pp = for k=1 to 10 collect (point size:5 axistripod:off pos:[10*cos(a = random 0 360), 10*sin(a),0] wirecolor:yellow) in coordsys world about [0,0,0] rotate pp (eulerangles (random 0 90) (random 0 90) 0) p = point size:10 axistripod:on transform:(multipointTM pp) wirecolor:green

Last edited by denisT : 04-24-2013 at 06:04 PM.
 
Old 04-24-2013, 06:04 PM   #5
denisT
MAX Doctor
 
denisT's Avatar
portfolio
Denis Trofimov
CA, USA
 
Join Date: Jul 2009
Posts: 9,308
Send a message via ICQ to denisT
to be absolutely correct we have to check matrix rotation (angle between vector1 and vector2) to make right matrix every time.
 
Old 04-24-2013, 06:07 PM   #6
JokerMartini
Expert
 
JokerMartini's Avatar
portfolio
John Martini
CG Supervisor, 3D, Maxscript, VFX
Ingenuity Engine
Los Angeles, USA
 
Join Date: Mar 2009
Posts: 1,299
Send a message via AIM to JokerMartini
Quote:
Originally Posted by denisT
to be absolutely correct we have to check matrix rotation (angle between vector1 and vector2) to make right matrix every time.


Is this an edit that needs to be handled in the function?

Seemingly works just as expected.
__________________
____________ ___ __ _
John A. Martini
JokerMartini@hotmail.com
www.JokerMartini.com
 
Old 04-24-2013, 06:17 PM   #7
denisT
MAX Doctor
 
denisT's Avatar
portfolio
Denis Trofimov
CA, USA
 
Join Date: Jul 2009
Posts: 9,308
Send a message via ICQ to denisT
Quote:
Originally Posted by JokerMartini
Is this an edit that needs to be handled in the function?

Seemingly works just as expected.

it's about Z vector... if way from point1 to point2 is CW Z(up) vector will look Up, if CCW it will look Down... or inversely...
 
Old 04-24-2013, 06:22 PM   #8
JokerMartini
Expert
 
JokerMartini's Avatar
portfolio
John Martini
CG Supervisor, 3D, Maxscript, VFX
Ingenuity Engine
Los Angeles, USA
 
Join Date: Mar 2009
Posts: 1,299
Send a message via AIM to JokerMartini
I see what your saying.
So then users can control if the objects Z axis is pointing in the right direction. So if need be they can flip it.

Seems like something worth putting as an option on the function.
__________________
____________ ___ __ _
John A. Martini
JokerMartini@hotmail.com
www.JokerMartini.com
 
Old 04-24-2013, 06:29 PM   #9
gazybara
Architect
 
gazybara's Avatar
portfolio
Branko Živković
Freelancer
Niš, Serbia
 
Join Date: Apr 2011
Posts: 1,103
Quote:
Originally Posted by denisT
so we need at least two vectors to make a matrix.
one vector is from center to the first point
second could be from center to second point...
in this case the matrix is:
Code:
fn multipointTM points = if points.count > 1 do ( center = [0,0,0] for p in points do center += p.pos center /= points.count front = normalize (points[1].pos - center) side = normalize (points[2].pos - center) up = normalize (cross front side) -- orthogonalized up side = normalize (cross up front) -- orthogonalized side tm = matrix3 front side up center ) delete objects pp = for k=1 to 10 collect (point size:5 axistripod:off pos:[10*cos(a = random 0 360), 10*sin(a),0] wirecolor:yellow) in coordsys world about [0,0,0] rotate pp (eulerangles (random 0 90) (random 0 90) 0) p = point size:10 axistripod:on transform:(multipointTM pp) wirecolor:green

I just tried yore method and seems that center position in not on the right plase.
Look at the sphere position
Maybe I'm wrong but just try this
Code:
fn multipointTM points = if points.count > 1 do ( center = [0,0,0] for p in points do center += p.pos center /= points.count front = normalize (points[1].pos - center) side = normalize (points[2].pos - center) up = normalize (cross front side) -- orthogonalized up side = normalize (cross up front) -- orthogonalized side tm = matrix3 front side up center ) delete objects rot = (eulerangles (random 0 90) (random 0 90) 0) guide = splineShape name:"TestShape" vertexTicks:on addNewSpline guide pp = for k=1 to 10 collect ( rndPos = [10*cos(a = random 0 360), 10*sin(a),0] addKnot guide 1 #corner #line rndPos point size:5 axistripod:off pos:rndPos wirecolor:yellow ) in coordsys world about [0,0,0] (rotate pp rot ; rotate guide rot) guide.pivot = guide.center ; updateshape guide ; sphere radius:1 pos:guide.center p = point size:10 axistripod:on transform:(multipointTM pp) wirecolor:green
__________________
Looking in the right side. [bgaTools]
 
Old 04-24-2013, 06:37 PM   #10
denisT
MAX Doctor
 
denisT's Avatar
portfolio
Denis Trofimov
CA, USA
 
Join Date: Jul 2009
Posts: 9,308
Send a message via ICQ to denisT
Quote:
Originally Posted by gazybara
I just tried yore method and seems that center position in not on the right plase.

what i calculate calls physical center (or center of mass). you are talking about geometrical center (center of bounding box)
 
Old 04-24-2013, 06:45 PM   #11
gazybara
Architect
 
gazybara's Avatar
portfolio
Branko Živković
Freelancer
Niš, Serbia
 
Join Date: Apr 2011
Posts: 1,103
Quote:
Originally Posted by denisT
what i calculate calls physical center (or center of mass). you are talking about geometrical center (center of bounding box)

Ok, thanks Denis
I did not mean to interrupt I was just curious.
What's the advantage of the use of physical center?
__________________
Looking in the right side. [bgaTools]
 
Old 04-24-2013, 06:47 PM   #12
JokerMartini
Expert
 
JokerMartini's Avatar
portfolio
John Martini
CG Supervisor, 3D, Maxscript, VFX
Ingenuity Engine
Los Angeles, USA
 
Join Date: Mar 2009
Posts: 1,299
Send a message via AIM to JokerMartini
Quote:
Originally Posted by gazybara
Ok, thanks Denis
I did not mean to interrupt I was just curious.
What's the advantage of the use of physical center?



I would assume it boils down to whatever you prefer and what your's use is.
__________________
____________ ___ __ _
John A. Martini
JokerMartini@hotmail.com
www.JokerMartini.com
 
Old 04-24-2013, 06:55 PM   #13
feranti
Frequenter
Antoine Ferrieux
Paris, France
 
Join Date: Apr 2008
Posts: 208
Quote:
What's the advantage of the use of physical center?


In this case, the physical center will always be on the plane, even if points are randomly dispatched on the plane.
The geometrical center might not be on the plane.

I think...
 
Old 04-24-2013, 06:55 PM   #14
denisT
MAX Doctor
 
denisT's Avatar
portfolio
Denis Trofimov
CA, USA
 
Join Date: Jul 2009
Posts: 9,308
Send a message via ICQ to denisT
Quote:
Originally Posted by gazybara
What's the advantage of the use of physical center?

there is no any specific advantage... different tasks - different methods. usually physical center is used in algorithms where you need 'weighted' positions. Skin, or Soft Selection for example. I've used it because it's easier to calculate
 
Old 04-24-2013, 07:02 PM   #15
gazybara
Architect
 
gazybara's Avatar
portfolio
Branko Živković
Freelancer
Niš, Serbia
 
Join Date: Apr 2011
Posts: 1,103
Quote:
Originally Posted by denisT
there is no any specific advantage... different tasks - different methods. usually physical center is used in algorithms where you need 'weighted' positions. Skin, or Soft Selection for example. I've used it because it's easier to calculate

I see that you love to "confuse" people with your super formulas.
Thanks for that.
__________________
Looking in the right side. [bgaTools]
 
Thread Closed share thread


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

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 08:16 PM.


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