Skip to content

Commit

Permalink
update for version 0.9.0.2 (field, tension/spring, mesh)
Browse files Browse the repository at this point in the history
  • Loading branch information
sghr committed Sep 20, 2013
1 parent 395c268 commit 5dfe548
Show file tree
Hide file tree
Showing 57 changed files with 1,234 additions and 133 deletions.
28 changes: 22 additions & 6 deletions I2DCurveFieldGeo.java
Original file line number Diff line number Diff line change
Expand Up @@ -36,28 +36,38 @@ public class I2DCurveFieldGeo extends IFieldGeo implements I2DFieldI{
public I2DCurveFieldGeo(ICurveI crv, ICurveI fieldCrv){ curve = crv; fieldCurve = fieldCrv; }

/** get original field value out of curve parameter u */
public IVec2I get(IVecI v, double u){ return fieldCurve.pt(u).to2d(); }
public IVec2I get(IVecI pos, double u){ return fieldCurve.pt(u).to2d(); }

/** get original field value out of curve parameter u */
public IVec2I get(IVecI pos, IVecI vel, double u){ return get(pos,u); } // ignore vel as default

/** get 3D vector field value */
public IVec2I get(IVecI pos){ return get(pos,null); }

/** get 3D vector field value */
public IVec2I get(IVecI v){
double u = curve.u(v.to2d());
public IVec2I get(IVecI pos, IVecI vel){
double u = curve.u(pos.to2d());
double r = intensity;
if(decay == Decay.Linear){
double dist = curve.pt(u).to2d().dist(v.to2d());
double dist = curve.pt(u).to2d().dist(pos.to2d());
if(dist >= threshold) return new IVec2(); // zero
if(threshold>0) r *= (threshold-dist)/threshold;
}
else if(decay == Decay.Gaussian){
double dist = curve.pt(u).to2d().dist(v.to2d());
double dist = curve.pt(u).to2d().dist(pos.to2d());
if(threshold>0) r *= Math.exp(-2*dist*dist/(threshold*threshold));
}

IVec2I vec = get(v,u);
IVec2I vec = get(pos,vel,u);

if(bidirectional && vec.get().dot(vel.to2d()) < 0){ r=-r; }

if(constantIntensity){
double len = vec.len();
if(len<IConfig.tolerance){ return vec.zero(); }
return vec.len(r);
}

return vec.mul(r);

/*
Expand Down Expand Up @@ -102,6 +112,11 @@ else if(decay == Decay.Gaussian){
/** if output vector is besed on constant length (intensity) or variable depending geometry when curve or surface tangent is used */
public I2DCurveFieldGeo constantIntensity(boolean b){ super.constantIntensity(b); return this; }

/** if bidirectional is on, field force vector is flipped when velocity of particle is going opposite */
public I2DCurveFieldGeo bidirectional(boolean b){ super.bidirectional(b); return this; }



/** set no decay */
public I2DCurveFieldGeo noDecay(){ super.noDecay(); return this; }
/** set linear decay; When distance is equal to threshold, output is zero.*/
Expand All @@ -116,6 +131,7 @@ public I2DCurveFieldGeo gaussianDecay(double threshold){
super.gaussianDecay(threshold); return this;
}
public I2DCurveFieldGeo gaussian(double threshold){ super.gaussian(threshold); return this; }
public I2DCurveFieldGeo gauss(double threshold){ super.gauss(threshold); return this; }

public I2DCurveFieldGeo threshold(double t){ super.threshold(t); return this; }
public I2DCurveFieldGeo intensity(double i){ super.intensity(i); return this; }
Expand Down
10 changes: 9 additions & 1 deletion I2DField.java
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,11 @@ abstract public class I2DField extends IField implements I2DFieldI{
public I2DFieldI field;
public I2DField(I2DFieldI f){ field=f; }
public IVec2I get(IVecI pt){ return field.get(pt); }
public void applyField(IParticleI p){ p.push(get(p.pos()).to3d()); }
public IVec2I get(IVecI pt, IVecI vel){ return field.get(pt,vel); }

//public void applyField(IParticleI p){ p.push(get(p.pos()).to3d()); }
public void applyField(IParticleI p){ p.push(get(p.pos(),p.vel()).to3d()); }

public I2DFieldI field(){ return field; }
/** set no decay */
public I2DField noDecay(){ field.noDecay(); return this; }
Expand All @@ -46,6 +50,7 @@ abstract public class I2DField extends IField implements I2DFieldI{
public I2DField gaussianDecay(double threshold){ field.gaussianDecay(threshold); return this; }
/** alias of gaussianDecay */
public I2DField gaussian(double threshold){ return gaussianDecay(threshold); }
public I2DField gauss(double threshold){ return gaussianDecay(threshold); }

/** this returns current decay type */
//public Decay decay();
Expand All @@ -54,6 +59,9 @@ abstract public class I2DField extends IField implements I2DFieldI{
/** if output vector is besed on constant length (intensity) or variable depending geometry when curve or surface tangent is used */
public I2DField constantIntensity(boolean b){ field.constantIntensity(b); return this; }

/** if bidirectional is on, field force vector is flipped when velocity of particle is going opposite */
public I2DField bidirectional(boolean b){ field.bidirectional(b); return this; }


/** set decay threshold */
public I2DField threshold(double t){ field.threshold(t); return this; }
Expand Down
3 changes: 2 additions & 1 deletion I2DFieldI.java
Original file line number Diff line number Diff line change
Expand Up @@ -32,5 +32,6 @@

public interface I2DFieldI extends IFieldI{
/** get field value at 3D location */
public IVec2I get(IVecI v);
public IVec2I get(IVecI pos);
public IVec2I get(IVecI pos, IVecI vel);
}
31 changes: 23 additions & 8 deletions I2DSurfaceFieldGeo.java
Original file line number Diff line number Diff line change
Expand Up @@ -41,15 +41,21 @@ public I2DSurfaceFieldGeo(ISurfaceI srf, ISurfaceI fieldSrf){


/** get original field value out of curve parameter u */
public IVec2I get(IVecI v, IVec2I uv){ return fieldSurface.pt(uv).to2d(); }
public IVec2I get(IVecI pos, IVec2I uv){ return fieldSurface.pt(uv).to2d(); }

/** get original field value out of curve parameter u */
public IVec2I get(IVecI pos, IVecI vel, IVec2I uv){ return fieldSurface.pt(uv).to2d(); }

/** get 3D vector field value */
public IVec2I get(IVecI v){ return get(v,(IVecI)null); }

/** get 3D vector field value */
public IVec2I get(IVecI v){
//IVec2I uv = surface.uv(v.to2d());
IVec2 uv = surface.uv(v.to2d()).get();
public IVec2I get(IVecI pos, IVecI vel){
//IVec2I uv = surface.uv(pos.to2d());
IVec2 uv = surface.uv(pos.to2d()).get();
double r = intensity;
if(decay == Decay.Linear){
double dist = surface.pt(uv).to2d().dist(v.to2d());
double dist = surface.pt(uv).to2d().dist(pos.to2d());
if(dist >= threshold &&
(uv.x<=0||uv.y<=0||uv.x>=1.0||uv.y>=1.0)) return new IVec2(); // zero
//(uv.x<IConfig.parameterTolerance || uv.y<IConfig.parameterTolerance ||
Expand All @@ -58,18 +64,21 @@ public IVec2I get(IVecI v){
if(threshold>0) r *= (threshold-dist)/threshold;
}
else if(decay == Decay.Gaussian){
double dist = surface.pt(uv).to2d().dist(v.to2d());
double dist = surface.pt(uv).to2d().dist(pos.to2d());
if(threshold>0) r *= Math.exp(-2*dist*dist/(threshold*threshold));
}

IVec2I vec = get(v,uv);
IVec2I vec = get(pos, vel, uv);

if(bidirectional && vec.get().dot(vel.to2d()) < 0){ r=-r; }

if(constantIntensity){
double len = vec.len();
if(len<IConfig.tolerance){ return vec.zero(); }
return vec.len(r);
}
return vec.mul(r);

return vec.mul(r);

/*
switch(decay){
Expand Down Expand Up @@ -118,6 +127,10 @@ else if(decay == Decay.Gaussian){
/** if output vector is besed on constant length (intensity) or variable depending geometry when curve or surface tangent is used */
public I2DSurfaceFieldGeo constantIntensity(boolean b){ super.constantIntensity(b); return this; }

/** if bidirectional is on, field force vector is flipped when velocity of particle is going opposite */
public I2DSurfaceFieldGeo bidirectional(boolean b){ super.bidirectional(b); return this; }


/** set no decay */
public I2DSurfaceFieldGeo noDecay(){ super.noDecay(); return this; }
/** set linear decay; When distance is equal to threshold, output is zero.*/
Expand All @@ -135,6 +148,8 @@ public I2DSurfaceFieldGeo gaussianDecay(double threshold){
public I2DSurfaceFieldGeo gaussian(double threshold){
super.gaussian(threshold); return this;
}
public I2DSurfaceFieldGeo gauss(double threshold){ super.gauss(threshold); return this; }

public I2DSurfaceFieldGeo threshold(double t){ super.threshold(t); return this; }
public I2DSurfaceFieldGeo intensity(double i){ super.intensity(i); return this; }

Expand Down
5 changes: 5 additions & 0 deletions I2DSurfaceNormalField.java
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,12 @@ public static class I2DSurfaceNormalFieldGeo extends I2DSurfaceFieldGeo{
public I2DSurfaceNormalField linear(double threshold){ super.linear(threshold); return this; }
public I2DSurfaceNormalField gaussianDecay(double threshold){ super.gaussianDecay(threshold); return this; }
public I2DSurfaceNormalField gaussian(double threshold){ super.gaussian(threshold); return this; }
public I2DSurfaceNormalField gauss(double threshold){ super.gauss(threshold); return this; }
public I2DSurfaceNormalField constantIntensity(boolean b){ super.constantIntensity(b); return this; }

/** if bidirectional is on, field force vector is flipped when velocity of particle is going opposite */
public I2DSurfaceNormalField bidirectional(boolean b){ super.bidirectional(b); return this; }

public I2DSurfaceNormalField threshold(double t){ super.threshold(t); return this; }
public I2DSurfaceNormalField intensity(double i){ super.intensity(i); return this; }
}
4 changes: 4 additions & 0 deletions I2DSurfacePositionField.java
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,11 @@ static public class I2DSurfacePositionFieldGeo extends I2DSurfaceFieldGeo{
public I2DSurfacePositionField linear(double threshold){ super.linear(threshold); return this; }
public I2DSurfacePositionField gaussianDecay(double threshold){ super.gaussianDecay(threshold); return this; }
public I2DSurfacePositionField gaussian(double threshold){ super.gaussian(threshold); return this; }
public I2DSurfacePositionField gauss(double threshold){ super.gauss(threshold); return this; }
public I2DSurfacePositionField constantIntensity(boolean b){ super.constantIntensity(b); return this; }
/** if bidirectional is on, field force vector is flipped when velocity of particle is going opposite */
public I2DSurfacePositionField bidirectional(boolean b){ super.bidirectional(b); return this; }

public I2DSurfacePositionField threshold(double t){ super.threshold(t); return this; }
public I2DSurfacePositionField intensity(double i){ super.intensity(i); return this; }
}
5 changes: 5 additions & 0 deletions I2DSurfaceSlopeField.java
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,12 @@ public IVec2I get(IVecI v, IVec2I uv){
public I2DSurfaceSlopeField linear(double threshold){ super.linear(threshold); return this; }
public I2DSurfaceSlopeField gaussianDecay(double threshold){ super.gaussianDecay(threshold); return this; }
public I2DSurfaceSlopeField gaussian(double threshold){ super.gaussian(threshold); return this; }
public I2DSurfaceSlopeField gauss(double threshold){ super.gauss(threshold); return this; }

public I2DSurfaceSlopeField constantIntensity(boolean b){ super.constantIntensity(b); return this; }
/** if bidirectional is on, field force vector is flipped when velocity of particle is going opposite */
public I2DSurfaceSlopeField bidirectional(boolean b){ super.bidirectional(b); return this; }

public I2DSurfaceSlopeField threshold(double t){ super.threshold(t); return this; }
public I2DSurfaceSlopeField intensity(double i){ super.intensity(i); return this; }
}
5 changes: 5 additions & 0 deletions I2DSurfaceUTangentField.java
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,12 @@ static public class I2DSurfaceUTangentFieldGeo extends I2DSurfaceFieldGeo{
public I2DSurfaceUTangentField linear(double threshold){ super.linear(threshold); return this; }
public I2DSurfaceUTangentField gaussianDecay(double threshold){ super.gaussianDecay(threshold); return this; }
public I2DSurfaceUTangentField gaussian(double threshold){ super.gaussian(threshold); return this; }
public I2DSurfaceUTangentField gauss(double threshold){ super.gauss(threshold); return this; }

public I2DSurfaceUTangentField constantIntensity(boolean b){ super.constantIntensity(b); return this; }
/** if bidirectional is on, field force vector is flipped when velocity of particle is going opposite */
public I2DSurfaceUTangentField bidirectional(boolean b){ super.bidirectional(b); return this; }

public I2DSurfaceUTangentField threshold(double t){ super.threshold(t); return this; }
public I2DSurfaceUTangentField intensity(double i){ super.intensity(i); return this; }

Expand Down
4 changes: 4 additions & 0 deletions I2DSurfaceVTangentField.java
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,11 @@ static public class I2DSurfaceVTangentFieldGeo extends I2DSurfaceFieldGeo{
public I2DSurfaceVTangentField linear(double threshold){ super.linear(threshold); return this; }
public I2DSurfaceVTangentField gaussianDecay(double threshold){ super.gaussianDecay(threshold); return this; }
public I2DSurfaceVTangentField gaussian(double threshold){ super.gaussian(threshold); return this; }
public I2DSurfaceVTangentField gauss(double threshold){ super.gauss(threshold); return this; }
public I2DSurfaceVTangentField constantIntensity(boolean b){ super.constantIntensity(b); return this; }
/** if bidirectional is on, field force vector is flipped when velocity of particle is going opposite */
public I2DSurfaceVTangentField bidirectional(boolean b){ super.bidirectional(b); return this; }

public I2DSurfaceVTangentField threshold(double t){ super.threshold(t); return this; }
public I2DSurfaceVTangentField intensity(double i){ super.intensity(i); return this; }

Expand Down
11 changes: 10 additions & 1 deletion I3DField.java
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,12 @@ abstract public class I3DField extends IField implements I3DFieldI{
public I3DFieldI field;
public I3DField(I3DFieldI f){ field=f; }
public IVecI get(IVecI pt){ if(field==null){ return null; } return field.get(pt); }
public void applyField(IParticleI p){ p.push(get(p.pos())); }

public IVecI get(IVecI pt, IVecI vel){ if(field==null){ return null; } return field.get(pt,vel); }

//public void applyField(IParticleI p){ p.push(get(p.pos())); }
public void applyField(IParticleI p){ p.push(get(p.pos(),p.vel())); }

public I3DFieldI field(){ return field; }
/** set no decay */
public I3DField noDecay(){ if(field!=null){ field.noDecay(); } return this; }
Expand All @@ -46,12 +51,16 @@ abstract public class I3DField extends IField implements I3DFieldI{
public I3DField gaussianDecay(double threshold){ if(field!=null){ field.gaussianDecay(threshold); } return this; }
/** alias of gaussianDecay */
public I3DField gaussian(double threshold){ return gaussianDecay(threshold); }
/** alias of gaussianDecay */
public I3DField gauss(double threshold){ return gaussianDecay(threshold); }
/** this returns current decay type */
//public Decay decay();


/** if output vector is besed on constant length (intensity) or variable depending geometry when curve or surface tangent is used */
public I3DField constantIntensity(boolean b){ if(field!=null){ field.constantIntensity(b); } return this; }
/** if bidirectional is on, field force vector is flipped when velocity of particle is going opposite */
public I3DField bidirectional(boolean b){ if(field!=null){ field.bidirectional(b); } return this; }


/** set decay threshold */
Expand Down
5 changes: 4 additions & 1 deletion I3DFieldI.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,5 +30,8 @@

public interface I3DFieldI extends IFieldI{
/** get field value at 3D location */
public IVecI get(IVecI v);
public IVecI get(IVecI pos);
/** get field value at 3D location with velocity */
public IVecI get(IVecI pos, IVecI vel);

}
4 changes: 4 additions & 0 deletions IAttractor.java
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,11 @@ static public class IAttractorGeo extends IPointFieldGeo{
public IAttractor linear(double threshold){ super.linear(threshold); return this; }
public IAttractor gaussianDecay(double threshold){ super.gaussianDecay(threshold); return this; }
public IAttractor gaussian(double threshold){ super.gaussian(threshold); return this; }
public IAttractor gauss(double threshold){ super.gauss(threshold); return this; }
public IAttractor constantIntensity(boolean b){ super.constantIntensity(b); return this; }
/** if bidirectional is on, field force vector is flipped when velocity of particle is going opposite */
public IAttractor bidirectional(boolean b){ super.bidirectional(b); return this; }

public IAttractor threshold(double t){ super.threshold(t); return this; }
public IAttractor intensity(double i){ super.intensity(i); return this; }

Expand Down
6 changes: 5 additions & 1 deletion IAttractorGeo.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,14 +31,18 @@

public class IAttractorGeo extends IPointFieldGeo{
public IAttractorGeo(IVecI p){ super(p,null); }
public IVecI get(IVecI v, IVecI orig){ return orig.dif(v); }
public IVecI getForce(IVecI v, IVecI orig){ return orig.dif(v); }

public IAttractorGeo noDecay(){ super.noDecay(); return this; }
public IAttractorGeo linearDecay(double threshold){ super.linearDecay(threshold); return this; }
public IAttractorGeo linear(double threshold){ super.linear(threshold); return this; }
public IAttractorGeo gaussianDecay(double threshold){ super.gaussianDecay(threshold); return this; }
public IAttractorGeo gaussian(double threshold){ super.gaussian(threshold); return this; }
public IAttractorGeo gauss(double threshold){ super.gauss(threshold); return this; }
public IAttractorGeo constantIntensity(boolean b){ super.constantIntensity(b); return this; }
/** if bidirectional is on, field force vector is flipped when velocity of particle is going opposite */
public IAttractorGeo bidirectional(boolean b){ super.bidirectional(b); return this; }

public IAttractorGeo threshold(double t){ super.threshold(t); return this; }
public IAttractorGeo intensity(double i){ super.intensity(i); return this; }
}
9 changes: 9 additions & 0 deletions IBounds.java
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,14 @@ public IBounds(double x, double y, double z, double xwidth, double yheight, doub
compare(p.add(xwidth,yheight,zdepth));
}

public IBounds(IObject[] objects){
for(int i=0; i<objects.length; i++){ compare(objects[i]); }
}

public IBounds(ArrayList<IObject> objects){
for(int i=0; i<objects.size(); i++){ compare(objects.get(i)); }
}


public IVec min(){ return min; }
public IVec getMin(){ return min(); }
Expand Down Expand Up @@ -100,6 +108,7 @@ public void compare(IVec p){

public void compare(IObject e){
synchronized(e){

if(!e.visible()) return; // if e is in the middle of constructor, this should be false.

if(e instanceof IPoint){
Expand Down
14 changes: 14 additions & 0 deletions ICircle.java
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,15 @@ public static IVec[] ovalCPApprox(IVec center, IVec xaxis, IVec yaxis){
return ICircleGeo.ovalCPApprox(center,xaxis,yaxis);
}

public static ICircle circumcircle(IVecI pt1, IVecI pt2, IVecI pt3){
return new ICircle(ICircleGeo.circumcircle(pt1,pt2,pt3));
}

public static ICircle circumcircle(IServer s, IVecI pt1, IVecI pt2, IVecI pt3){
return new ICircle(s,ICircleGeo.circumcircle(pt1,pt2,pt3));
}


//ICircleGeo circle;

public ICircle(IVecI center, IVecI normal, IDoubleI radius){
Expand Down Expand Up @@ -170,6 +179,8 @@ public ICircle(IVecI center, IVecI xradiusVec, IVecI yradiusVec, boolean approx)
this((IServerI)null,center,xradiusVec,yradiusVec,approx);
}

public ICircle(ICircleGeo cir){ super(cir); }


public ICircle(IServerI s, IVecI center, IVecI normal, IDoubleI radius){
super(s, new ICircleGeo(center,normal,radius,radius,false));
Expand Down Expand Up @@ -274,6 +285,9 @@ public ICircle(IServerI s, IVecI center, IVecI xradiusVec, IVecI yradiusVec, boo
super(s,new ICircleGeo(center,xradiusVec,yradiusVec,approx));
}

public ICircle(IServerI s, ICircleGeo cir){ super(s,cir); }



// name(), layer(), clr() etc.

Expand Down
8 changes: 8 additions & 0 deletions ICircleGeo.java
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,14 @@ public static IVec[] ovalCPApprox(IVec center, IVec xaxis, IVec yaxis){
}


public static ICircleGeo circumcircle(IVecI pt1, IVecI pt2, IVecI pt3){
IVec center = IVec.circumcenter(pt1.get(),pt2.get(),pt3.get());
double rad = center.dist(pt1);
IVec nml = pt1.get().nml(pt2,pt3);
return new ICircleGeo(center,nml,rad);
}



public IVecI center;
public IVecI normal;
Expand Down
Loading

0 comments on commit 5dfe548

Please sign in to comment.