c# - Calculate rotation acording to drag of one edge -
my code in c# (silverlight) might have nothing it. i'm trying rotate element draging 1 of edges. in event got dx , dy values tried calculate vector rotation center drag start , other 1 center new location, , calculate angle between vectors, didn't work. correct way such thing?
edit: mbo asked code try calculate angle between 2 vectors. lets v[vx, vy]
vector rotation center draged edge, vc[vcx, vcy]
vector of drag change. third vector v1[v1x, v1y]
rotation center 'new' location of draged edge.
normv = math.sqrt(vx * vx + vy * vy) normv1 = math.sqrt(v1x * v1x + v1y * v1y) vv1 = vx*v1x+vy*v1y // dot product of v , v1 vectors // fi angle shoudl fi = math.acos(vv1 / (normv * normv1))
your code gives angle in half-range 0..pi, necessary add angle sign cross product.
let's (x0,y0) - initial captured point, (x1,y1) - after dragging, (cx, cy) - rotation center.
dx0 = x0-cx dy0 = y0-cy dx1 = x1-cx dy1 = y1-cy rotationangle = math.atan2(dx0 * dy1 - dx1 * dy0, dx0 * dx1 + dy0 * dy1)
Comments
Post a Comment