Matching Axis from Position points

Become a member of the CGSociety

Connect, Share, and Learn with our Large Growing CG Art Community. It's Free!

THREAD CLOSED
 
Thread Tools Search this Thread Display Modes
  04 April 2013
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.




(
	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
 
  04 April 2013
are all points at the same plane? are they flatten?
 
  04 April 2013
yes they are all flat and on the same plane Denis.
__________________
____________ ___ __ _
John A. Martini
JokerMartini@hotmail.com
www.JokerMartini.com
 
  04 April 2013
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:

  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 April 2013 at 06:04 PM.
 
  04 April 2013
to be absolutely correct we have to check matrix rotation (angle between vector1 and vector2) to make right matrix every time.
 
  04 April 2013
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
 
  04 April 2013
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...
 
  04 April 2013
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
 
  04 April 2013
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:

   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

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]
 
  04 April 2013
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)
 
  04 April 2013
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]
 
  04 April 2013
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
 
  04 April 2013
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...
 
  04 April 2013
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
 
  04 April 2013
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



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 01:23 AM.


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