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

Atividades 2
Deus não se preocupe das nossas dificuldades matemáticas.
Ele integra empiricamente.
Einstein.

Hipérboles e suas Assintodas

Considere os Hiperboles:
[; \left( \frac{x}{a} \right)^2 - \left( \frac{y}{b} \right)^2 =1 \quad \Leftrightarrow \quad x = \pm a \sqrt{1+\left( \frac{y}{b} \right)^2} ;]
Uma parametrização alternativa as funções hiperbólicas é:
[; \underline{\textbf{r}}(t)= \begin{pmatrix} a \sqrt{1+\left( \frac{t}{b} \right)^2}\\ t \end{pmatrix}, \quad t \in \mathbb{R} ;]
Desenhe uma sequencia de hiperboles com [;a=1;] e valores de [;b;] tanto maiores como menores de 1.
Python Listing: ../../../Code/Hyperbola.py.
from math import *

from Vector import *
from Curve  import Curve

class Hyperbola(Curve):
    Name="Hyperbola"
    
    #Center
    C=Vector([0.0,0.0])

    #Parameters
    a=1.0
    b=0.0

    t1=-2.0
    t2=2.0
    
    def __init__(self,a=1.0,b=0.0,C=None,NP=0):
        if (C):  self.C=C
        if (NP): self.NP=NP
        
        self.a=a
        self.b=b

        return
    
    def R_Hyp(self,t):
        return Vector([
            self.C[0]+self.a*cosh(t),
            self.C[1]+self.a*sin(t),
        ])
    
    def R(self,s):
        return Vector([
            self.C[0]+self.a*sqrt(1.0+s**2.0),
            self.C[1]+self.b*s
        ])

    def Assymptotes(self):
        xm=self.a*sqrt(1.0+self.t2**2.0)
        ym=self.b*xm/(1.0*self.a)

        return [
            [
                self.C+Vector([-xm,-ym]),
                self.C+Vector([ xm, ym])
            ],
            [
                self.C+Vector([ xm,-ym]),
                self.C+Vector([-xm, ym])
            ]
        ]
        
    def Assymptotes_SVG(self,options):
        svg=[]
        for assymptote in self.Assymptotes():
            px1=curve.Canvas.Point_2_Pixels(assymptote[0])
            px2=curve.Canvas.Point_2_Pixels(assymptote[1])
            
            svg.append(  self.SVG_Line(px1,px2,options)   )
            
        return svg       

    def PMin(self):
        xymin=min(-self.a*sqrt(1.0+self.t2**2.0),-20.0*self.t2)
        return Vector([xymin,xymin])
    
    def PMax(self):
        xymax=min(self.a*sqrt(1.0+self.t2**2.0),20.0*self.t2)
        return Vector([xymax,xymax])
Python Listing: ../../../Code/Hyperbolas.py.
from Vector  import *
from Hyperbola import Hyperbola

C=O()
a=2.0

b1=1.0
b2=20.0

N=100

db=1.0*(b2-b1)/( 1.0*(N-1) )

A=[
    [-1.0,0.0 ],
    [ 0.0,1.0 ],
]

R=[
    [-1.0,0.0 ],
    [ 0.0,1.0 ],
]
RR=[
    [ 1.0,0.0 ],
    [ 0.0,-1.0] ,
]

def PMin():
    xymin=-2.0*b2
    return Vector([xymin,xymin])
def PMax():
    xymax=2.0*b2
    return Vector([xymax,xymax])



b=b1

svgfiles=[]
curve=None

for n in range(N):
    curve=Hyperbola(a,b,C,N)
    curve.Rs()

    curve.Init_Canvas(PMin(),PMax())

    fname="Hyperbola/"+("%03d" % n)+".svg"
    options={
        "stroke": 'blue',
        "style": {
            "stroke-width": 2,
        }
    }
    svg=[]
    
    #Hyperbolas embracing X

    #Left hand part
    rsm=Map_Linears(A,curve.rs,True)
    
    svg=svg+curve.Curve_SVG_Line(options,curve.rs)
    svg=svg+curve.Curve_SVG_Line(options,rsm)
    
    #Hyperbolas embracing Y
    rsp=curve.rs
        
    options[ "stroke" ]='green'
    
    #Upper part
    rsp=Map_Linears(R,curve.rs,True)
    
    svg=svg+curve.Curve_SVG_Line(
        options,
        rsp
    )
    
     #Lower part
    rrsp=Map_Linears(RR,rsp,True)
    
    #svg=svg+curve.Curve_SVG_Line(
    #    options,
    #    rrsp
    #)
    
    options[ "stroke" ]='red'
    assymptotes=curve.Assymptotes()
    for assymptote in assymptotes:
        px1=curve.Canvas.Point_2_Pixels(assymptote[0])
        px2=curve.Canvas.Point_2_Pixels(assymptote[1])
        svg=svg+[ curve.SVG_Line(px1,px2,options) ]
            
    

    curve.SVG_2_File(fname,svg)
    svgfiles.append(fname)
    
    b+=db
curve.Curve_Carousel(svgfiles)
Messages:
0 secs.