graph - How to rotate a function and get coordinates in python? -


https://postimg.org/image/uzdalt4s1/

the script below give coordinates of point going through sine function (figure in url image)

similar figure a, how coordinates of rotated function? (figure b)

from time import sleep import math  x = 100 y = 500 f = 0  while 1:     print('x: '+str(x))     print('y: '+str(math.sin(f)*100+y))     f += math.pi/50     x += 1     sleep(0.01) 

this should work:

from time import sleep import math  def get_rotated_coordinates(x, y, fi, angle = 'deg'):     ''' function rotates coordinates x , y angle fi, variable     angle tells if angle fi in degrees or radians, default value     'deg' degrees, can use 'rad' radians'''      if angle == 'deg':         fi = math.radians(fi)     elif angle != 'rad':         raise valueerror('{} unsuported type angle.\nyou can use "deg" degrees , "rad" radians.'.format(angle))      k = math.tan(fi)     denominator = math.sqrt(k**2 + 1)     x1 = x / denominator     y1 = k * x1     x2 = -(y * k / denominator) + x1     y2 = (x1 - x2) / k + y1      return x2, y2  x = 100 y = 500 f = 0 while 1:     y = math.sin(f)*100+y     x2, y2 = get_rotated_coordinates(x, y, 30)     print('x: '+str(x2))     print('y: '+str(y2))     f += math.pi/50     x += 1     sleep(0.01) 

Comments

Popular posts from this blog

How to start daemon on android by adb -

testing - Detect whether test has failed within fixture -

Angularjs unit testing - ng-disabled not working when adding text to textarea -