rotation - How to get the angle to rotate a line in python -


I have a line with two points [x1, y1, x2, y2] and I have a new point (nx , NY) on which I rotate the first line and then move it forward.

Here's the picture to get it: Enter image details here

I have tried with this function but I can not manage to complete the rotation, using I''tteter and Python:

  DEF rotate line (Self, Dx, DI): There are differences between # X and Y x1, NX and Y1, NE angle = mathematics.Tan 2 (DI, DX) print "angle", ang NewX = ((X1) * Math.cos (angle) - (y1) * math.sin (angle)) newy = ((x1) * math.sin (angle) + (y1) * math.cos (angle)) self.panel. Coouls (self, robot, newx, new, new + 10, new + 30) # I always add 10 in X and 30 in the wi so that the line size is maintained. Panel. Update ()    

I'm not familiar with TkInter, but it looks like an educated guess That for the input itself Panel. There are handle and four coordination for the calls line. By setting coordination (x, y, x + 10, y + 30), you always make a line segment of the same length and angle, you are actually setting, the only thing is the origin of the line.

Do you want to stretch the line (x1, y1) to (nx, nae) or to edge along the edge of the line between the edges?

In addition, when you calculate new and new, you need to focus it on the point (x1, y1). So, everywhere you have (x1), you need (x2-x1), and y1 is the same. You have to add x1 and y1 back again, because the formula you are using is for rotation about the original. The equation should be

  newx = ((x2-x1) * math.cos (angle) - (y2-y1) * math.sin (angle)) + x1 newy = ((x2 -x1) * math.sin (angle) + (y2-y1) * math.cos (angle)) + y1   

If you want to do the first thing, then rotate the line new point Section, then you should try

  Self.Panel.Cords (auto, robot, x1, y1, newx, new)   < P> The length of the line should have been preserved in the calculation of your new point. Transferring line segments is a simple matter of translating between vertical and distance between NewX, New and (NX, NY) using both points from angle.   

Comments

Popular posts from this blog

php - PDO bindParam() fatal error -

logging - How can I log both the Request.InputStream and Response.OutputStream traffic in my ASP.NET MVC3 Application for specific Actions? -

java - Why my included JSP file won't get processed correctly? -