Click here to Skip to main content
15,899,314 members
Please Sign up or sign in to vote.
2.00/5 (1 vote)
See more:
Hi there,

I'm tring to rotate a line in mfc., around its center.
this should be rotated as i click the mouse and move it.
heres the code for it.
please help me put.

where NewPoint is the mouse click point
and m_newStart is line start point

C#
double distY=abs(m_NewPoint.y);
double distX=abs(m_NewPoint.x);
double theta=(abs(atan(distY/distX))*180/3.14);

m_newStart.x  = MdPt.x + (StPt.x-MdPt.x)*(cos(theta)) - (StPt.y-MdPt.y)*(sin(theta));
m_newStart.y  = MdPt.y  +  (-1)*(StPt.x-MdPt.x)*(sin(theta)) - (StPt.y-MdPt.y) * cos(theta));

m_newEnd.x  = MdPt.x -  (StPt.x-MdPt.x)*(cos(theta)) + (StPt.y-MdPt.y)*(sin(theta));
m_newEnd.y  = MdPt.y  -  (-1)*(StPt.x-MdPt.x)*(sin(theta)) + (StPt.y-MdPt.y)*(cos(theta));
Posted
Updated 19-Apr-15 20:23pm
v3

1 solution

Calculate X and Y by this code (java). Use sin and cos in C++ (include math.h).
SQL
 x = center + radius * Math.sin( angle );
 y = center - radius * Math.cos( angle );
}
 
Share this answer
 
Comments
Member 11484810 20-Apr-15 6:52am    
there's no radius over here.
And Does it apply to both the point co-ordinates??
Style-7 20-Apr-15 7:49am    
radius = line lengh
center = coord. of mouse

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900