import java.io.Reader; import java.io.Writer; /** * Implementat ion of * interface for specifying per-agent information neccessary to * perform formation morphing to morph to a rectangle with a * "comb" topology. Rect width is specified at construction time. * @author Michael Schuresko * @version %I%, %G% * @since 1.0 */ public class MorphSpecCardioid implements IMorphSpec { double m_lfDist; /** * defaults for the first demo */ public MorphSpecCardioid() { m_lfDist = 0.2; } public MorphSpecCardioid(double lfSpacing) { m_lfDist = lfSpacing; } public double [] getFinalUv(int nAgentId) { double [] arrLfUv = new double[2]; if(nAgentId == 0) { arrLfUv[0] = arrLfUv[1] = 0.0; } else if(nAgentId <= 8) { double lfscaleDist = m_lfDist*(nAgentId); arrLfUv[1] = lfscaleDist*Math.cos(0.25*(8-nAgentId)*0.125); arrLfUv[0] = lfscaleDist*Math.sin(0.25*(8-nAgentId)*0.125); } else { double lfscaleDist = m_lfDist*(nAgentId-8); arrLfUv[1] = lfscaleDist*Math.cos(0.25*(16-nAgentId)*0.125); arrLfUv[0] = lfscaleDist*Math.sin(-0.25*(16-nAgentId)*0.125); } return arrLfUv; } public int getNumChildren(int nAgentId) { if(nAgentId == 0) { return 2; } return 1; } public int getTopoLastVisit(int nAgentId) { if(nAgentId == 0) { return 33; } if(nAgentId <= 8) { return nAgentId + 2*(8-nAgentId)+1; } return 16+(nAgentId-8)+2*(8-(nAgentId-8))+1; } public int getTopoFirstVisit(int nAgentId) { if(nAgentId <= 8) { return nAgentId; } return 16+nAgentId; } public int getTopoDepth(int nAgentId) { if(nAgentId <= 8) { return nAgentId; } return (nAgentId-8); } /* * 8 is just a guess here * (non-Javadoc) * @see IMorphSpec#getMaxDepth() */ public int getMaxDepth() { return 8; } /** * Make this more then a stub later */ public void dump(Writer writeTo) {} /** * Make this more then a stub later */ public void load(Reader readFrom) {} }