![Antiguo](http://static.forosdelweb.com/fdwtheme/images/statusicon/post_old.gif)
17/02/2010, 12:15
|
| | Fecha de Ingreso: noviembre-2001 Ubicación: México DF
Mensajes: 128
Antigüedad: 23 años, 2 meses Puntos: 0 | |
Respuesta: Coordenadas de un rectángulo Gracias LynxCraft,
Pero el problema no es dibujar un rectángulo, sino determinar las coordenadas correctas para el dibujo del mismo tomando como base un punto de inicio y otro final... ojo: es muy diferente un rectángulo horizontal a uno con inclinación, se necesita una ecuación lineal.
En kirupa.com recibí la siguiente respuesta, pero la verdad, no entendí como hacerlo. it's standard linear equation...
a line (with no end points) is defined as a point with a slope
two lines that are parallel have the same slope but pass through different points
the if you know two points on a line, you can easily deduce the slope as the delta in each dimension... or in 2d as the ratio of rise to run
Some other things that may be useful:
slope can be defined as a vector... < i, j> where i is the dt of x, and j is the dt of y.
to rotate a vector 90 degrees in 2d, you just swap i and j, and set either i or j negative.
multiplying a scalar (number) by a vector is performed piecewise... C<i,j> == <ci, cj>
adding two vectors is performed piecewise... <i1,j1> + <i2,j2> == <i1 + i2, j1 + j2>
So say you have xStart, yStart, xEnd, yEnd
the slope is: <xEnd - xStart, yEnd - yStart>
this vector points from start to end, the length OR magnitude of this vector is the length of the rectangle.
length = sqrt(i*i + j*j) //simple pythagorean
if we take a unit vector from this:
slopeVector / length == < i / len, j / len >
this vector is of length 1... we can now scale this vector easily to whatever length we want... in your image we're looking for 5. But FIRST we want to rotate it 90 degrees!
< j, -i> / len
now we scale it
offset = 5 * <j, -i> / len
now if we add this to <startX, startY> we get the BL, if we subtract if from <startX, startY> we get TL. If we add this to <endX, endY> we get BR, if we subtract it from <endX, endY> we got TR.
There you have your 4 points.
OR you could just get the 2 left points, and add the slopeVector to both of them to get the right points.
It's all relative... you essentially defined free floating vectors describing all 4 sides of the rectangle.
Alguna sugerencia de como llevar esto a actionscript???
Saludos!!! |