Python - Alguien con tiempo libre? Mini-proyecto de -50 lineas

 
Vista:

Alguien con tiempo libre? Mini-proyecto de -50 lineas

Publicado por Arturo Balbuena (1 intervención) el 21/11/2013 03:49:51
Hola amigos, estoy haciendo unos mini-proyectos que encontré en una página de una universidad de habla inglesa.

Hasta ahora llevo una buena parte del código, pero en la parte de aplicar matemáticas no entiendo nada, ya que la forma en que se explica (en inglés) no logro entender como obtener 2 puntos de una línea.

Bueno aquí les dejo la descripción en PDF: http://www.cse.msu.edu/~cse231/PracticeOfComputingUsingPython/01_Beginnings/SecondWeekProjects/TurtleGraphicsAngles/project02.pdf

Aquí mi código: (Que por consejo lo escribo todo en inglés)
En pastebin para los que les gusta el color de la sintaxis: http://pastebin.com/sWiuk16i

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
import turtle
 
def check_if_valid(var):
    while True:
        if var.isdigit():
            break
        else:
            var = input('Enter a valid number ->')
 
 
def get_x_and_y():
    x = input('\'x\' coordinate -> ')
    check_if_valid(x)
    y = input('\'y\' coordinate -> ')
    check_if_valid(y)
    return [int(x),int(y)]
 
print('This program will read in 2 points, and draw 2 lines. \n\
Then it will calculate the acute (smaller) angle \n\
between the 2 lines you draw.')
 
# get coordinates
 
 
print('1st point')
point1 = get_x_and_y()
print('2nd point')
point2 = get_x_and_y()
 
# calculates the acute angle
 
up = point2[1] - point1[1]
down = point2[0] - point1[0]
m = up / down
'''Aquí el problema! ¿Cómo obtener 2 puntos por cada línea?'''
 
# start drawing
turtle.title('Angle Calculator')
 
#multiplicados por 4 para hacer las líneas más grandes.
turtle.goto(point1[0] * 4, point1[1] * 4) #goes to the first point
turtle.goto(point2[0] * 4, point1[1] * 4) # goes to the second point
 
turtle.done()


Espero que alguien lo pueda hacer, o ayudarme a entender como sacar 2 puntos de una línea:

Finding the angle between 2 lines:
You are required to calculate the acute angle between 2 lines. In order to do that you need to
determine the slope of each line, and the slope of a line is “rise/run” or
where (x1, y1) and (x2, y2) are 2 points on the line.


Gracias!
Valora esta pregunta
Me gusta: Está pregunta es útil y esta claraNo me gusta: Está pregunta no esta clara o no es útil
0
Responder