#Copyright (C) 2012 Francisco Chamiça Pereira #Escola Secundária da Ramada # #This program is free software; you can redistribute it and/or modify it under #the terms of the GNU General Public License as published by the Free Software #Foundation; either version 2 of the License, or (at your option) any later #version. # #This program is distributed in the hope that it will be useful, but WITHOUT #ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS #FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. # from visual import * scene.height=1500 scene.width=1400 #menu de escolhas condicao=1 while condicao==1: escolha=input('(A) Um looping\n(B) Dois loopings\nInsira a opção ') if escolha not in ['A','a','B','b']: print('Escolha entre as opções dadas\n') else: while condicao==1: raio=input('Insira o raio do looping ') try: float(raio) if float(raio)<1: print ('Insira valores positivos e superiores a 1\n') else: raio=float(raio) if escolha in ['b','B']: while 1: raio2=input('Insira o raio do segundo looping ') try: float(raio2) if float(raio2)<1: print('Insira valores positivos e superiores a 1') else: raio2=float(raio2) condicao=2 break except: print('Insira valores válidos') else: condicao=2 break except: print('Insira valores válidos\n') if escolha in ['A','a']: hmin=2.5*raio if escolha in ['B','b']: if raio>raio2: hmin=2.5*raio else: hmin=2.5*raio2 while 1: print('Altura mínima = ',hmin) h=input('Insira a altura inicial (m) = ') condicao=0 try: float(h) if float(h)>hmin+2 or float(h)<4: print ('\nAtribua valores numéricos entre 4 e',hmin+2,' para a altura (m) ') else: h=float(h) break except: print('Insira valores válidos\n') #objetos bola=sphere(color=color.green,radius=0.5) bola.pos=(-10-raio+bola.radius-3,h+bola.radius,0) #rampa rampa = frame() rampa1=box(frame=rampa,pos=(-3,0,(hmin+2)/2),size=(0.1,1.5,hmin+2)) curva=extrusion(frame=rampa,pos=paths.arc(pos=(0,0,0),angle1=pi/2,angle2=pi),shape=shapes.rectangle(width=0.1, height=1.5)) rampa.rotate(angle=pi/2, axis=(-1,0,0), origin=(0,0,0)) rampa.pos.y=rampa.pos.y+3-0.07 rampa.pos.x=rampa.pos.x-10-raio #continuacao continuacao = box(pos=(-(10+raio)/2,-0.07,0), size=(10+raio,0.14,1.3,)) #looping 1 looping=frame() no=-0.55 n=0 nf=0.55 while nlooping2.x: py=bola.radius+raio2 w=v/raio2 angulo=-pi/2 at=0 mov=5 elif (v<0 and escolha in ['A','a'] and situacao==1) or (v>0 and situacao==2): break while mov==5: rate(1000) w=w+at*dt angulo=angulo+w*dt at=g*sin(angulo+pi/2)/raio2 bola.x=looping2.x+raio2*cos(angulo) bola.y=py+raio2*sin(angulo) bola.z=((-1.3/(2*pi))*(angulo+pi/2))+1.3 v=w*raio2 an=(v**2)/raio2 Velocidade.text=('Velocidade (m/s) = '+str("%.2f" % v)) if angulo>=(3*pi/2): ax=-h*3 #atrito vx=v vy=0 ay=0 mov=2.1 situacao=2 elif w<0 and angulo<-pi/2: final.material=materials.bricks ax=h*3 ay=0 vx=v vy=0 mov=2.1 situacao=2 elif w>0 and an<-g*sin(angulo): vx=-v*sin(angulo) vy=v*cos(angulo) ay=g ax=0 mov=2.1 situacao=1 while mov==2.1: rate(1000) vx=vx+ax*dt vy=vy+ay*dt bola.x=bola.x+vx*dt bola.y=bola.y+vy*dt v=sqrt(vx**2+vy**2) Velocidade.text=('Velocidade (m/s) = '+str("%.2f" % v)) if (bola.x<(-(raio2/2)+looping2.x) or bola.y< raio2-raio2/4) and situacao==1: label(pos=(bola.pos),text='ERRO, a bola saiu da calha') break if (vx>=0 and ax>0) or (vx<=0 and ax<0): break