2016-09-11 8 views
0

回転角を指定してストライプパターンを描画したいと思います。私は縦線を描画する方法を考えましたが、回転させませんでした。例えば、45度の入力で以下の画像が与えられた場合、私は第2の画像を生成したいと思います。ここで回転ストライプパターンを描画する方法

は、第1の画像を生成するための私のコードです:将来輸入部門から

import numpy as np 
import matplotlib.pyplot as plt 
%matplotlib inline 
stripe_width = 15 
gap = 20 
offset = 2 
image_size = 250 

canvas = np.zeros((image_size, image_size)) 
current_col = 0 
while current_col < image_size: 
    if current_col + stripe_width + gap <= image_size-1: 
     canvas[:, current_col:current_col+stripe_width] = 1 
     current_col += stripe_width + gap 
    elif current_col + stripe_width <= image_size-1: 
     canvas[:, current_col:current_col+stripe_width] = 1 
     current_col = image_size 
    else: 
     canvas[:, current_col:] = 1 
     current_col = image_size 

plt.imshow(canvas) 

そしてここでは、私のコードから出力される画像です: Current Output

そして、ここでは、私が回転した画像をしたいものです次のように表示されます。 Desired Output

ご意見はありますか?

+1

ご使用のプロットライブラリに質問し、タグを付ける必要があります。 – martineau

+0

私は実際に特定のライブラリでプロットしていません。ほとんどの場合、np行列を1と0で埋めて –

答えて

0

centerについては、回転方法が必要です。例えば、以下のサンプルメソッドがあります。必要に応じて修正する必要がありますが、コードを開始するには十分でなければなりません。

def rotate_point(center, point, angle): 
     """Rotate point around center by angle 
     Args: 
      center: 
       Center point (tuple, [x,y]) 
      point: 
       Point to be rotated (tuple, [x,y]) 
      angle: 
       Angle in radians to rotate by 

     Returns: 
      New coordinates for the point 
     """ 
     angle = math.radians(angle) 
     temp_point = point[0]-center[0] , point[1]-center[1] 
     temp_point = (-temp_point[0]*math.cos(angle)+temp_point[1]*math.sin(angle) , temp_point[0]*math.sin(angle)-temp_point[1]*math.cos(angle)) 
     temp_point = [temp_point[0]+center[0] , temp_point[1]+center[1]] 
     return temp_point 
関連する問題