i need to rotate the direction of a vector by 90 degrees, i found a rotation matrix in 2d space :
a = angle
| cos a - sin a |
| sin a cos a |
so therefor rotation by 90 deg is :
|0 -1|
|1 0|
the thing is : how do i multiply a matrix with a vector ???
i know that a matrix is calculated like this :
|a1 a2|
|b1 b2| = a1b2 - a2b1
which results in a number, but if i multiply this number with a vector i will get only bigger vector in the same direction
i could also use a link to a good math tutorial
and one more question :
why does a full circle has 360 degrees why wouldn't an angle value be between 0 and 1 ??? doesn't it seem more logical
PS : i really need a good math tutorial
(U) (a b) (u) (a*u + b*v) (-v)
(V) = (c d) (v) = (c*u + d*v) = ( u) (if a=d=0, b=-c=-1)
PS : you're right about the tutorial ;)
You could start by reading this: http://www.siggraph.org/education/materials/HyperGraph/modeling/mod_tran/3drota.htm
On the other hand, what you call calculate a matrix is really only the determinant. That is more or less a way to know how big that matrix turns things once it has been multiplied by a vector.
To multiply a matrix times a vector see: http://www.facstaff.bucknell.edu/mastascu/eLessonsHTML/Circuit/MatVecMultiply.htm which includes a nice animated GIF on how to do it.
Finally, IMHO, angles should always be computed in radians and not in degrees, since radians are a lot more intuitive than degrees which are arbitrary. http://www.teacherschoice.com.au/Maths_Library/Angles/Angles.htm
Hope you can find good Math tutorials, since Math is such a nice topic everybody just hates because their teachers hated it too… (Ok… this is just a personal assumption, sorry) Wiki is a good place to start, perhaps.
Good luck
duenez said:
You could start by reading this: http://www.siggraph.org/education/materials/HyperGraph/modeling/mod_tran/3drota.htm
On the other hand, what you call calculate a matrix is really only the determinant. That is more or less a way to know how big that matrix turns things once it has been multiplied by a vector.
To multiply a matrix times a vector see: http://www.facstaff.bucknell.edu/mastascu/eLessonsHTML/Circuit/MatVecMultiply.htm which includes a nice animated GIF on how to do it.
Finally, IMHO, angles should always be computed in radians and not in degrees, since radians are a lot more intuitive than degrees which are arbitrary. http://www.teacherschoice.com.au/Maths_Library/Angles/Angles.htm
Hope you can find good Math tutorials, since Math is such a nice topic everybody just hates because their teachers hated it too... (Ok... this is just a personal assumption, sorry) Wiki is a good place to start, perhaps.
Good luck
thanks for the help
The Librarian said:
(U) (a b) (u) (a*u + b*v) (-v)
(V) = (c d) (v) = (c*u + d*v) = ( u) (if a=d=0, b=-c=-1)
PS : you're right about the tutorial ;)
i'm not a computer, i'm a human
Well it's still the general formula for matrix / vector multiplication in 2 dimensions
Agreed, a little explanation would not have hurt, but I've never done any math in English, so…
(and my remark about the tutorial was just that everyone could use such tutorials - thanks duenez! )
thanks everyone, i'm begining to love math.
it's so logical…
Sasa said:
thanks everyone, i'm begining to love math.
it's so logical...
Hmmm!, Kind of like programming?
i have another problem. i have to calculate an intersection point between two lines ( i'm making my own physics library )
first i tried to find a tutorial, but there was some stuff unexplained so i just looked for finished code ( i'm gonna ask my math teacher tommorow )
so i tried following ( it's in java script, i ported it to python for my own use )
Intersection.intersectLineLine = function(a1, a2, b1, b2) {
var result;
var ua_t = (b2.x - b1.x) * (a1.y - b1.y) - (b2.y - b1.y) * (a1.x - b1.x);
var ub_t = (a2.x - a1.x) * (a1.y - b1.y) - (a2.y - a1.y) * (a1.x - b1.x);
var u_b = (b2.y - b1.y) * (a2.x - a1.x) - (b2.x - b1.x) * (a2.y - a1.y);
if ( u_b != 0 ) {
var ua = ua_t / u_b;
var ub = ub_t / u_b;
if ( 0 <= ua && ua <= 1 && 0 <= ub && ub <= 1 ) {
result = new Intersection("Intersection");
result.points.push(
new Point2D(
a1.x + ua * (a2.x - a1.x),
a1.y + ua * (a2.y - a1.y)
)
);
} else {
result = new Intersection("No Intersection");
}
} else {
if ( ua_t == 0 || ub_t == 0 ) {
result = new Intersection("Coincident");
} else {
result = new Intersection("Parallel");
}
}
return result;
};
and it doesn't work, i get some random intersection point, or i don't get it when lines are intersecting
note that my coord system is 2d and it's like this :
0 x
>
|
|
|
|
y /
duenez said:
Sasa said:
thanks everyone, i'm begining to love math.
it's so logical...
Hmmm!, Kind of like programming?
in some way, but it isn't exactly defined like in programming, things can vary ( it's like a more Python like version of Python )
Unfortunately I am extremely lazy and don't plan to read through your Python code because I don't want to understand what do you mean when you say things like ua_t and b2.y
Instead, I will point you to a Java function that does what you want… Given lines in the form of two points (x0,y0) and (x1,y1)
public Point2D.Float intersect(float x0,float y0,float x1,float y1, float x2,float y2,float x3,float y3)
{
float a1,b1,c1, // constants of linear equations
a2,b2,c2,
det_inv, // the inverse of the determinant of the coefficient matrix
m1,m2; // the slopes of each line
// compute slopes, note the cludge for infinity, however, this will
// be close enough
if ((x1-x0)!=0)
m1 = (y1-y0)/(x1-x0);
else
m1 = (float)1e+10; // close enough to infinity
if ((x3-x2)!=0)
m2 = (y3-y2)/(x3-x2);
else
m2 = (float)1e+10; // close enough to infinity
// compute constants
a1 = m1;
a2 = m2;
b1 = -1;
b2 = -1;
c1 = (y0-m1*x0);
c2 = (y2-m2*x2);
// compute the inverse of the determinate
det_inv = 1/(a1*b2 - a2*b1);
// use Kramers rule to compute x and y for the intersection
Point2D.Float pt = new Point2D.Float();
pt.x=((b1*c2 - b2*c1)*det_inv);
pt.y=((a2*c1 - a1*c2)*det_inv);
return pt;
} // end Intersect_Lines
duenez said:
Unfortunately I am extremely lazy and don't plan to read through your Python code because I don't want to understand what do you mean when you say things like
no that's Java script, and here's the python version :
def getInters(self, vektor):
a1x = self.poz.x# * 100
a1y = self.poz.y# * 100
a2x = (self.poz.x + self.smjer.x)#*100
a2y = (self.poz.y + self.smjer.y)#*100
b1x = vektor.poz.x# * 100
b1y = vektor.poz.y# * 100
b2x = (vektor.poz.x + vektor.smjer.x)#*100
b2y = (vektor.poz.y + vektor.smjer.y)#*100
poz = Poz()
ua_t = (b2x - b1x) * (a1x - b1x) - (b2y - b1y) * (a1x - b1x)
ub_t = (a2x - a1x) * (a1y - b1y) - (a2y - a1y) * (a1x - b1x)
u_b = (b2y - b1y) * (a2x - a1x) - (b2x - b1x) * (a2y - a1y)
if u_b != 0:
ua = ua_t / u_b
ub = ub_t / u_b
#if 0 <= ua and ua <= 1 and 0 <= ub and ub <= 1:
if True:
poz.x = a1x + ua * (a2x - a1x)
poz.y = a1y + ua * (a2y - a1y)
return poz
return None
( couldn't resist, it's in my blood :P)
anyhow, i'm gonna try your function out when i return from school today...
and thanks for all your help, again.