Question

Ohh.. damm Math !! once again stuck. It seems to be easy but i think its not that easy, Problem Statement: I want to rotate the 3 fixed points which lies on a fixed circle. 1.when 1 point is selected remaining 2 points should be static mode and only selected point should move/rotate on circumference of circle. 2.And all 3 points are connected via 3 lines as shown in images..when we select a point and rotate it,connected lines also increase and decrease..

I already tried to solve this problem finding angle at each instant after touch.but its not quite working as per my need..

something like this enter image description here

enter image description here enter image description here

enter image description here

Was it helpful?

Solution

I hope the following explanation enable you to put the steps into your coding language.

Presumption is that the vertex to be moved has already selected and so the calculation of (xcnd,ycnd) as defined below is used to set the selected vertex of the triangle.

Let the constraining circle have centre at (cx,cy) and radius r.

Let the coordinates of where the screen is touched be (xtch,ytch)

Let the coordinates of where the screen is touched relative to the centre be (xrel,yrel)

then xrel = xtch - cx and yrel = ytch - cy

Let the coordinates of the point on the constraining circle when the screen is touched at (xtch,ytch) be (xcnd,ycnd).

xcndrel = xcnd - cx, and ycndrel = ycnd - cy give the coordinates on the constraining circle relative to its centre,

Note that

xrel and xcndrel will have the same signs (ie both positive or both negative)

and yrel and ycndrel will also have the same signs.

the function abs(x) = x if x>=0 and -x if x<0 should be available in whatever language you are using

the function sign(x) may or may not be available, sign(x) =1 if x>0 and -1 if x<0 and undefined for x=0

If not available then sign(x)=x/abs(x)

Check if xrel=0

if xrel=0 xcndrel=0, ycndrel=r*sign(yrel)

Otherwise work in first quadrant ie where x>0 and y>0 using abs(xrel) and abs(yrel)

find angle where screen is touched relative to centre of circle using

theta=arctan(abs(yrel)/abs(xrel))

find the coordinates (xcndrel, ycndrel) by using theta in the first quadrant and then placing in the correct quadrant using the signs of xrel and yrel

xcndrel = sign(xrel)*r*COS(theta)

ycndrel = sign(yrel)*r*SIN(theta)

Screen coordinates can now be found

xcnd = xcndrel +cx

ycnd = ycndrel + cy

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top