• 🏆 Texturing Contest #33 is OPEN! Contestants must re-texture a SD unit model found in-game (Warcraft 3 Classic), recreating the unit into a peaceful NPC version. 🔗Click here to enter!
  • 🏆 Hive's 6th HD Modeling Contest: Mechanical is now open! Design and model a mechanical creature, mechanized animal, a futuristic robotic being, or anything else your imagination can tinker with! 📅 Submissions close on June 30, 2024. Don't miss this opportunity to let your creativity shine! Enter now and show us your mechanical masterpiece! 🔗 Click here to enter!

Need an idea! Vector math ?

Status
Not open for further replies.
Level 11
Joined
Jan 2, 2016
Messages
472
example.png


What i have familiar is the angle alpha, point P1 and point P2, i also have a function that calculates the perpedicular distance showed here. I want to know in which direction the vector is going referent to the P1 ? Now this varies where P2 is and the angle alpha. Basically if it's direction is left or right watching from the point P1.
 
Level 11
Joined
Jan 2, 2016
Messages
472
@GhostWolf already provided a solution for this: ( Bx - Ax) * (Cy - Ay) - (By - Ay) * (Cx - Ax)

Untitled.jpg


The drawing was a bit confusing at first i must say.


@Dr Super Good If you've got any other ideas i'm all ears. Basically i have an object that kind of represents a vector and it is defined by a origin point ( P2 in my original picture ) and an angle.One thing i didn't mention is that it is always pointed outwards from P2.
 
Last edited:
Level 11
Joined
Jan 2, 2016
Messages
472
unknown.png


Let's say a man is standing on P1 and looking at the vector F. Where does vector F point to left or right ?
This is what i need to find out. Now note that the line on which the vector F is can be on any side of the point with any angle, i just drew these two cases for simplicity.
 
Level 14
Joined
Jan 16, 2009
Messages
716
A vector can be treated as a direction or a point. if you are looking at a vector then you treat it as a point and as such it has no direction.
If the vector is a direction you can easily find the angle of its direction : Atan2(y,x) where y and x are the coordinates of the vector.
 
Level 29
Joined
Jul 29, 2007
Messages
5,174
Note that the math I posted is the determinant of the 2x2 matrix holding the vectors AB and AC.

If the result is a negative, C is on one side of AB.
If the result is a positive, C is on the other side of AB.
If the result is 0, C is on AB.

Which side corresponds to negative or positive results depends on how you store your data and do operations.

As a side note, if the vectors are normalized, the results will be normalized too and will be equal to -1, 0, or 1.

You can also check the angle between AB and AC with arc tangent like Wareditor mentioned. It's probably more intuitive.
 
Last edited:

Dr Super Good

Spell Reviewer
Level 64
Joined
Jan 18, 2005
Messages
27,229
Note that the math I posted is the determinant of the 2x2 matrix holding the vectors AB and AC.

If the result is a negative, C is on one side of AB.
If the result is a positive, C is on the other side of AB.
If the result is 0, C is on AB.
Thanks for the clarification. I knew some steps were missing lol...

Technically the determinant approach would be fastest as it allows some level of instruction parallelism. Specifically the subtractions can be executed in parallel, followed by both multiplications, the final subtraction and then the comparisons giving a worst case path length of 2 subtractions, 1 multiplication and the comparison. It is pretty reasonable to assume that branch prediction for the comparison will often be wrong, but when it is correct it will result in as good as no path length (executed as fast as the instructions can be read).

Anything involving arc tangent is almost certainly going to be slower as that is a highly complex function and even if implemented at an instruction level will have a comparatively huge execution time compared with 2 subtractions and a multiplication. Especially if the angle has to have a modulus applied to it before comparison since modulus and division instructions are some of the slowest common instructions.

I know this is almost certainly pointless to mention, but just in case someone finds this stuff interesting.
 
Status
Not open for further replies.
Top