Cross Product

Post any maths and/or physics related questions here.

Moderators: Darobat, RecursiveS, Dante Shamest, Bugdude, Wizard

Cross Product

Postby Samuel » Sat Mar 04, 2006 3:09 am

Ive having trouble getting a collision detection algorithm to work in 3D. When I walk around in the 3D world, it detects collisions all sorts of weird places. I think the problem is comming from the cross product function because everything but this is copied from previous projects. The code is supposed to return a normal for a plane.

Code: Select all
class vec
{
    public:
        float x, y, z;
};

vec crossproduct(float Ax, float Ay, float Az, float Bx, float By, float Bz)
{
    vec vector;
    vector.x = (Ay*Bz)-(By*Az);
    vector.y = -(Ax*Bz)+(Bx*Az);
    vector.z = (Ax*By)-(Ay*Bx);
    return vector;
}

[/code]
But apart from the sanitation, the medicine, education, wine, public order, irrigation, roads, the fresh-water system, and public health, what have the Romans ever done for us?
User avatar
Samuel
 
Posts: 676
Joined: Wed Apr 06, 2005 7:43 pm
Location: Australia

Postby schloob » Sat Mar 04, 2006 10:22 am

cross product:
Code: Select all
| i  j  k  |
| x1 y1 z1 |
| x2 y2 z2 |


figure out if it's right

*edit* blah typos
Last edited by schloob on Sat Mar 04, 2006 11:14 am, edited 1 time in total.
:]
User avatar
schloob
 
Posts: 1853
Joined: Mon Feb 16, 2004 10:29 am
Location: Seattle

Postby Jack Brown » Sat Mar 04, 2006 10:31 am

What is that schloob? That is not correct. Looks like you're taking the cross product of two vectors in R^2 (which yet is the wrong way since the cross product of two 2D vectors is det(u, v)). The correct version should be

|e1 e2 e3|
|x1 y1 z1 |
|x2 y2 z2 |

Edit: Your version would also be correct if we took (x1, y1, x1)x(x2, y2, x2)
But how often does the first element equal the last one?
Last edited by Jack Brown on Sat Mar 04, 2006 11:27 am, edited 1 time in total.
Jack Brown
 
Posts: 103
Joined: Sun Feb 19, 2006 1:12 pm
Location: Sweden

Postby schloob » Sat Mar 04, 2006 11:14 am

oh whoops, that second x was supposed to be a z, the characters look so similar i didn't notice it. whoopsies!
:]
User avatar
schloob
 
Posts: 1853
Joined: Mon Feb 16, 2004 10:29 am
Location: Seattle

Postby Samuel » Sat Mar 04, 2006 5:41 pm

i kind of suck a lot at maths. Is what I posted right or wrong? if its wrong, whats wrong with it?
But apart from the sanitation, the medicine, education, wine, public order, irrigation, roads, the fresh-water system, and public health, what have the Romans ever done for us?
User avatar
Samuel
 
Posts: 676
Joined: Wed Apr 06, 2005 7:43 pm
Location: Australia

Postby Apocalypse » Wed Mar 08, 2006 1:25 pm

Cross Product:

vec vector;
vector.x = Ay*Bz - By*Az;
vector.y = Bx*Az - Ax*Bz;
vector.z = Ax*By - Ay*Bx;


... so I think it's pretty correct
Apocalypse, The End of The World
User avatar
Apocalypse
 
Posts: 78
Joined: Mon Jul 26, 2004 11:45 am
Location: Romania


Return to Maths & Physics

Who is online

Users browsing this forum: No registered users and 0 guests