Notifications
Clear all

[Closed] Geometrical calculations : points, lines, planes : intersections, distances, angles

The code I use for doing a look-at type operation is:

fn PointAxisAt a which_axis b =
(
local c = normalize (b - a) 
local angle = acos (dot which_axis c)
local axis = normalize (cross which_axis c)
 
local out = (angleaxis angle axis) as quat
out
)
 
a = $Pyramid01.position
b = $Point01.position
q = PointAxisAt a z_axis b
r = q * (inverse $Pyramid01.rotation)
rotate $Pyramid01 r

THought this might be the best topic to post it:

I have this camera data:
posz=-12.896441
posy=10.177296
posx=-248.952271

And this for the angle:
anglez=1.000000
angley=0.000000
anglex=0.000000

this is how they calculated the angle:
angle = camera_target – camera
angle = normalize angle
anglex = angle.x
angley = angle.y
anglez = angle.z

how would i go about transforming the angle from this data?
how can i create a target or free camera from this?

I prefer to rename “angle” in “direction” because the angle can remind the angle of the camera (fov)

thePos = [posx,posy,posz]
theDirection = [directionx,directiony,directionz]
theLength = 100.0
theTargetPos = thePos + ((normalize theDirection)*theLength)

myCam = targetCamera pos:thePos target:(targetObject pos:theTargetPos)

Regrettably your data are not complete : the camera’s FOV is missing.

Thanks for your reply but i already solved it. I did it slightly different though:

camera_target_position = point3 (posx + directionx10) (posy + directiony10) (posz + directionz*10)

Which returns the correct ‘direction’.

Oh and you dont need a FOV to create a camera, it uses default setting when you leave it out.

I just wanna give you two link for resources about geometry (intersections , distance computations etc):

http://www.softsurfer.com (algorithms section)
http://www.geometrictools.com

Hope this helps

Great thread! Seeing basic concepts as code snippets is fantastic!

I do think that the posting of questions (as opposed to answers) clutters the “repository” feel, though. For those asking (new and unrelated) questions wouldn’t it be more helpful to start and finish a new thread, THEN post (a concise answer) here?

This is being transferred to the CGWiki bit by bit, so the information can be kept clean:
http://wiki.cgsociety.org/index.php/Geometric_Calculations_(3dsmax)

Hy all,

I am new at maxscript and I want to calculate the shortest distance between a vertex in a skin and a bone. Can someone help me?

-edit-

ok, i modified pretty pixel’s code and got this:



fn pointSegmentDist pA pB pC = 
(
	local vAB=pB-pA
	local vAC=pC-pA
	local vBC=pC-PB
	
	local c1=dot vAB vAC
	local c2=dot vAB vAB
	
	if c1 < 0 do
		return length vAC
	
	if c2 < c1 do
		return length vBC
	
	(length (cross vAB vAC))/(length vAB)
)

not sure if it is 100% correct, i have other issues but will start a new thread for that.

 rdg

The Algorithmic Beauty of Plants can be downloaded here as PDF:
http://algorithmicbotany.org/papers/

This is the ‘definitve book’ about L-Systems (see also Challenge #16).
Sometimes you can find a printed version in ‘antique shops’ – get it!
I ordered mine some weeks ago, hope it arrives soon …

Georg

 rdg

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

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/ActionScriptLangRefV3/fl/transitions/easing/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

Page 3 / 7