1: package aliolci.CrazyBall;
2: /*
3: * By Ali Olcay SAHIN
4: * www.aliolci.com
5: * aliolci@gmail.com
6: * Thank you for using it.
7: * */
8: import java.util.ArrayList;
9: import java.util.List;
10:
11: import android.graphics.PointF;
12:
13: public class VectoralPathResolver { 14: private float FromXDelta, ToXDelta, FromYDelta, ToYDelta;
15: private float d =(float) 0.1;//sensitivity
16: private float realHypo;
17: private float hypo;
18: private double TanAngle;
19: private double cosValue;
20: private double sinValue;
21: private byte signX;
22: private byte signY;
23: public VectoralPathResolver(float fromXDelta, float toXDelta,
24: float fromYDelta, float toYDelta) { 25: FromXDelta = fromXDelta;
26: ToXDelta = toXDelta;
27: FromYDelta = fromYDelta;
28: ToYDelta = toYDelta;
29:
30: realHypo = (float) Math.sqrt(Math.pow(FromXDelta-ToXDelta, 2)+Math.pow(FromYDelta-ToYDelta, 2));
31: hypo =0;
32: TanAngle = Math.atan((ToYDelta-FromYDelta)/(ToXDelta-FromXDelta));
33: cosValue =Math.cos(TanAngle);
34: sinValue =Math.sin(TanAngle);
35: signX = (byte) (Integer.signum((int) (ToXDelta-FromXDelta))<0?-1:1);
36: signY = (byte) (Integer.signum((int) (ToYDelta-FromYDelta))<0?-1:1);
37: }
38: public List<PointF> ResolveReturnFullPath()
39: { 40: List<PointF> path= new ArrayList<PointF>();
41: PointF f;
42: do
43: { 44: f=this.Next();
45: if(f!=null)
46: path.add(f);
47: }
48: while(f!=null);
49:
50: return path;
51: }
52: public void setSensitivity(float sensitivity)
53: { 54: d=sensitivity;
55: }
56: public PointF Next()
57: { 58: if(realHypo>hypo)
59: { 60: hypo+=d;
61: float Xnew = (float)(cosValue*hypo*signX)+FromXDelta;
62: float Ynew =(float)(sinValue*hypo*signY)+FromYDelta;
63: return new PointF(Xnew,Ynew);
64: }
65: else
66: return null;
67: }
68: public PointF Next(int HowMuchEachTime)
69: { 70: if(realHypo>hypo)
71: { 72: hypo+=d*HowMuchEachTime;
73: float Xnew = (float)(cosValue*hypo*signX)+FromXDelta;
74: float Ynew =(float)(sinValue*hypo*signY)+FromYDelta;
75: return new PointF(Xnew,Ynew);
76: }
77: else
78: return null;
79: }
80: public void reset()
81: { 82: hypo=0;
83: }
84: public int getTotalSteps()
85: { 86: return (int)(realHypo/d);
87: }
88: }