Jump to content
  • Advertisement
Sign in to follow this  
Malamute

Vector Math help

This topic is 4114 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Sorry to be an annoying git, but I freakin suck at math, I've been struggling with this simple vector problem for about an hour now, so I just said fuck it and decided to post begging for help. Basically, I have 2 2d vectors. Each is described by an x and y coordinate. Let's call them Vec1 and Vec2. I have to extract a component vector from Vec2 that is perpendicular to Vec1. Here is a picture to illustrate: Sounds pretty simple but I can't seem to pull it off. Can somebody explain in really simple terms how to do this? It would be even better if you could write it in pseudocode.

Share this post


Link to post
Share on other sites
Advertisement
ORTHOGONAL(black,blue)

Project blue onto black
real factor = (dot blue black) / |black|
vector project = factor black

Substract the projection
return blue - project

Share this post


Link to post
Share on other sites
Quote:
Original post by RivieraKid
blue = black + pink
pink = blue - black

my lame guess. Could be wrong.


Unfortunately, this doesn't work for all vectors of varying magnitude that point in the same direction. It would work if the |v1|2 - |v2|2 = |v3|2, but we don't know if that is the case.

ToohrVyk has it right.

Share this post


Link to post
Share on other sites
Quote:
Original post by ToohrVyk
ORTHOGONAL(black,blue)

Project blue onto black
real factor = (dot blue black) / |black|
vector project = factor black

Substract the projection
return blue - project


Thanks. I translated your code into a c++ function. I'm not sure that it's done right though.


void Ortho(double vec1x,double vec1y,double vec2x,double vec2y) {
double factor = (vec1x*vec2x+vec1y*vec2y)/sqrt(vec1x*vec1x+vec1y*vec1y);

double projx=factor*vec1x;
double projy=factor*vec1y;

resultx=vec2x-projx;
resulty=vec2y-projy;
}

Share this post


Link to post
Share on other sites
I think I identified the problem. I just had to take out the sqrt sign and the thing gives the right output.

void Ortho(double vec1x,double vec1y,double vec2x,double vec2y) {
double factor = (vec1x*vec2x+vec1y*vec2y)/sqrt(vec1x*vec1x+vec1y*vec1y);

double projx=factor*vec1x;
double projy=factor*vec1y;

resultx=vec2x-projx;
resulty=vec2y-projy;
}

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!