Muestra las diferencias entre dos versiones de la página.
| Ambos lados, revisión anterior Revisión previa Próxima revisión | Revisión previa | ||
|
numbers:graphics [2011/03/10 19:13] alfred |
numbers:graphics [2020/05/09 09:25] (actual) |
||
|---|---|---|---|
| Línea 2: | Línea 2: | ||
| ===== Geometría ===== | ===== Geometría ===== | ||
| + | |||
| Línea 41: | Línea 42: | ||
| } | } | ||
| </code> | </code> | ||
| - | * **Distancia entre un punto y una línea** | + | * **Distancia entre un punto y una línea**, el siguiente código devuelve la distancia entre un punto P a la lína que pasa entre A y B: |
| <code java> | <code java> | ||
| + | public double pointToLineDistance(Point A, Point B, Point P) | ||
| + | { | ||
| + | double normalLength = Math.sqrt((B.x - A.x) * (B.x - A.x) + (B.y - A.y) * (B.y - A.y)); | ||
| + | return Math.abs((P.x - A.x) * (B.y - A.y) - (P.y - A.y) * (B.x - A.x)) / normalLength; | ||
| + | } | ||
| </code> | </code> | ||
| **Saber si dos líneas son paralelas** | **Saber si dos líneas son paralelas** | ||
| Línea 277: | Línea 283: | ||
| * [[http://freespace.virgin.net/hugo.elias/models/m_perlin.htm]] | * [[http://freespace.virgin.net/hugo.elias/models/m_perlin.htm]] | ||
| * [[http://devmag.org.za/articles/48-HOW-TO-USE-PERLIN-NOISE-IN-YOUR-GAMES/2/#top1]] | * [[http://devmag.org.za/articles/48-HOW-TO-USE-PERLIN-NOISE-IN-YOUR-GAMES/2/#top1]] | ||
| + | |||
| + | ===== Ecuaciones de formas ===== | ||
| + | ==== Elipse ==== | ||
| + | <code python> | ||
| + | import pygame | ||
| + | from pygame.locals import * | ||
| + | import sys | ||
| + | import math | ||
| + | w = 640 | ||
| + | h = 489 | ||
| + | screen = pygame.display.set_mode((w,h)) | ||
| + | |||
| + | sampling = 50 | ||
| + | r1 = 100 | ||
| + | r2 = 160 | ||
| + | |||
| + | def drawPoint (x,y, c=(255,0,0)): | ||
| + | centX = w/2 | ||
| + | centY = h/2 | ||
| + | nx = centX + x | ||
| + | ny = centY + y | ||
| + | pygame.draw.circle(screen, c, (int(nx), int(ny)), 1) | ||
| + | |||
| + | for i in range(sampling): | ||
| + | theta = i * (2. * 3.1421)/sampling | ||
| + | cosTheta = math.cos(theta) | ||
| + | sinTheta = math.sin(theta) | ||
| + | tmp1 = (cosTheta*cosTheta)/(r2*r2) | ||
| + | tmp2 = (sinTheta * sinTheta)/(r1*r1) | ||
| + | tmp = math.sqrt(tmp1+tmp2) | ||
| + | drawPoint(cosTheta/tmp, sinTheta/tmp) | ||
| + | |||
| + | pygame.display.flip() | ||
| + | |||
| + | while True: | ||
| + | for event in pygame.event.get(): | ||
| + | if event.type == QUIT: | ||
| + | sys.exit() | ||
| + | pygame.display.update() | ||
| + | </code> | ||