POV-Ray : Newsgroups : povray.advanced-users : Deformation gone awry Server Time
8 Jul 2024 18:38:24 EDT (-0400)
  Deformation gone awry (Message 1 to 1 of 1)  
From: David Wallace
Subject: Deformation gone awry
Date: 2 Aug 2006 18:16:04
Message: <44d12424@news.povray.org>
This macro allows attractors and/or repulsors to modify the positions of 
points in space.

// Optional functions
#declare dfNum = 7;
#declare dfLoc = array[dfNum] // Position of deformation
#declare dfStr = array[dfNum] // Strength of deformation (positive if 
attracting, negative if repelling)
#declare dfUni = array[dfNum] // Distance dependance, usually -2 (gravity)

#declare da = 0;
#while (da<5)
	#declare dfLoc[da] = vrotate(x*9,y*da*72);
	#declare dfStr[da] = 1;
	#declare dfUni[da] = -2;
	#declare da = da + 1;
#end
#declare dfLoc[5] = y*4;
#declare dfLoc[6] = -y*4;
#declare dfStr[5] = 3;
#declare dfStr[6] = -3;
#declare dfUni[5] = -2;
#declare dfUni[6] = -2;

#macro Deform1(trg,src,acc,uni)
	#local frc = vnormalize(src-trg)*acc*pow(vlength(trg-src),uni);
	frc
#end

#macro Deform(pos,tim,nstep)
	#local _ans = pos;
	#local _step = tim/nstep;
	#local _dt = 0;
	#while (_dt<tim)
		#local _dn = 0;
		#local _push = <0,0,0>;
		#while (_dn<dfNum)
			#local _push = _push + 
Deform1(_ans,dfLoc[_dn],dfStr[_dn]*_step,dfUni[_dn]);
			#local _dn = _dn + 1;
		#end
		#local _ans = _ans + _push;
		#local _dt = _dt + _step;
	#end
	_ans
#end

I ran into some trouble when some of the points came too close to the 
attractors and got flung too far in the other direction.


Post a reply to this message

Copyright 2003-2023 Persistence of Vision Raytracer Pty. Ltd.