SmtC: Show me the Code
Ole Peter Smith
Instituto de Matemática e Estatística
Universidade Federal de Goiás
http://www.olesmith.com.br

Matemática Computacional
Detetesto as vitimas
Quando elas respeitam os seus carrascos.
Jean Paul Sartre

Área de Desenho Geométricas: [; \underline{\textbf{p}}_1, \underline{\textbf{p}}_2 ;]

Resolução: [; R_1,R_2 ;]
  1. Pixels [; (0,0) ;]: Superior Esquerda
  2. Pixels [; (R_1,R_2) ;]: Inferior Direita

Transformação Afim

[; \begin{pmatrix}p_x\\p_y\end{pmatrix} = f \begin{pmatrix}x\\y\end{pmatrix} = \begin{pmatrix} a_1 x +b_1\\a_2 y+b_2\end{pmatrix} ;]

Condições:

[; f( \underline{\textbf{p}}_1 }) = \begin{pmatrix}0\\R_2\end{pmatrix} = \begin{pmatrix} a_1 x_1 +b_1\\a_2 y_1+b_2\end{pmatrix} ;]

[; f( \underline{\textbf{p}}_2 }) = \begin{pmatrix}R_1\\0\end{pmatrix} = \begin{pmatrix} a_1 x_2 +b_1\\a_2 y_2+b_2\end{pmatrix} ;]

Subtract:

[; \begin{pmatrix}R_1\\R_2\end{pmatrix} = \begin{pmatrix}a_1(x_2-x_1)\\a_2(y_1-y_2)\end{pmatrix} ;]

[; \begin{pmatrix}a_1\\a_2\end{pmatrix} = \begin{pmatrix}\frac{R_1}{x_2-x_1}\\\frac{R_2}{y_1-y_2}\end{pmatrix} ;]

[; \begin{pmatrix}b_1\\b_2\end{pmatrix} = \begin{pmatrix}-a_1x_1\\-a_2 y_2 \end{pmatrix} = \begin{pmatrix}R_2-a_2y_1\\R_1-a_1 x_2 \end{pmatrix} ;]

Python Listing: ../Code/Canvas2.py.
class Canvas2:

    P1=None
    P2=None
    R=None

    A=[0.0,0.0]
    B=[0.0,0.0]

    def __init__(self,r,p1,p2):
        self.R=r
        self.P1=p1
        self.P2=p2
        self.Initialize()

    def __str__(self):
       return str(self.P1)+" "+str(self.P2)+" "+str(self.R)+" "+str(self.A)+" "+ str(self.B)

    #Initialize Parameters A,B from R,P1 and P2
    
    def Initialize(self):
        self.A[0]=(1.0*(self.R[0] ))/(1.0*( self.P2[0]-self.P1[0] ))
        self.A[1]=(1.0*(self.R[1] ))/(1.0*( self.P1[1]-self.P2[1] ))
                                                   
        self.B[0]=-self.A[0]*self.P1[0]
        self.B[1]=-self.A[1]*self.P2[1]
        

    #Convert geometric point to pixels.
    
    def Point_2_Pixels(self,p):
        px=[0,0]
        for i in range(2):
            px[i]=self.A[i]*p[i]+self.B[i]
            
        return px
    
    #Convert geometric points to pixels.
    
    def Points_2_Pixels(self,ps):
        pxs=[]
        for p in ps:
            pxs.append(  self.Point_2_Pixels(p) )
            
        return pxs
Messages:
0 secs.