math - a way to search between some points and find important points -


i have points, in order, drawn user.

i want find important points between these points. important point, define, point have sudden change in direction of points. example, 'z' drawn hand, has has 2 important points.

i tried computing angle between adjacent points, not giving me desired result. , computing change in slope same.

maybe need optimize angle finding somehow, have no idea. idea?

edit: here java code compare angles:

int nbreakpoints = 0; double nextangle = 0; double nextr; double r = math.sqrt(math.pow(points[1].x-points[0].x, 2)      + math.pow(points[1].y-points[0].y, 2)); double angle = math.asin((points[1].y-points[0].y) / r)*180/math.pi;  double cumr = r; int firsti = 0; for(int i=1; i<points.length-2 ;i++) {     nextr = (int) math.sqrt(math.pow(points[i].x-points[i+1].x, 2)          + math.pow(points[i+1].y-points[i].y, 2));     cumr += nextr;     if(cumr < 20 || cumr==0) continue;     nextangle = math.asin((points[i].y-points[firsti].y) / cumr)*180/math.pi;     if(math.abs(angle-nextangle) >= 20) nbreakpoints++;     r = nextr;     angle = nextangle;     cumr = 0;     firsti = i; } 

ok, computes angle between 2 points, , if different 20 degrees, have new important point.

just note, cumr , firsti added prevent "too close" points brought computation.

your angle calculation may fail if angle flips 360°. e.g. 1 angle 179° , next 1 -179°. absolute difference pretty big, angles pretty close.

here more robust method:

pp = points[i - 1] //the preceding point; if exists p = points[i] pn = points[i + 1] //the next point; if exists dp = [p.x - pp.x, p.y - pp.y] //direction of incoming line dn = [pn.x - p.x, pn.y - p.y] //direction of outgoing line r = math.sqrt((dp.x * dp.x + dp.y * dp.y) * (dn.x * dn.x + dn.y * dn.y)) //product of vector lengths cos = (dp.x * dn.x + dp.y * dn.y) / r //cosine of angle angle = math.acos(cos) * 180 / math.pi; if(angle > 20)     ... 

if points near each other , subject noise, might reasonable consider wider range instead of adjacent points:

pp = points[i - n] p = points[i] pn = points[i + n] 

n can constant can choose based on application. next point distance current one:

for(int j = - 1; j >= 0; --j) {     dp = [p.x - points[j].x, p.y - points[j].y]     rp = dp.x * dp.x + dp.y * dp.y;     if(rp > square_threshold)         break; } 

... , same next point.


Comments

Popular posts from this blog

plot - Remove Objects from Legend When You Have Also Used Fit, Matlab -

java - Why does my date parsing return a weird date? -

Need help in packaging app using TideSDK on Windows -