crla / slimmath

Automatically exported from code.google.com/p/slimmath
0 stars 0 forks source link

Perp unary operator in Vector2D #8

Closed GoogleCodeExporter closed 8 years ago

GoogleCodeExporter commented 8 years ago
What steps will reproduce the problem?
1. Perp unary operator missing
2. Enhancement
3.

Please provide any additional information below.

The Perp operator is missing. It could be useful in some geometry algorithms.
Here is what I'm referring to:

        public static Vector2 Perp(Vector2 vector2)
        {
            return new Vector2(-vector2.Y, vector2.X);
        }

It returns a vector perpendicular to the input one.
If it was implemented, it could also be used to implement the "PerpDot" product 
or 2D cross product.

Also, are there any plans to implement a double precision Math library?

Original issue reported on code.google.com by avengerd...@gmail.com on 4 Nov 2010 at 9:13

GoogleCodeExporter commented 8 years ago
The Perp operator you are speaking of is technically the cross product in 2D. 
Because the binary form of the cross product (that gives a vector result) is 
only defined in 3 and 7 dimensions, a normal cross product for Vector2 does not 
exist. However, an 'artifical' cross product can be made for n dimensions by 
taking n-1 vector arguments and giving out a Vectorn result. This means that 
the Perp operator is technically the cross product in 2D. This is the reason we 
don't have a Cross product method in the Vector2 and Vector4 classes.

That aside I will implement the Perp operator and most likely the PerpDot 
operation for Vector2.

As for the double precision version of the library, it is not planned because 
C# does not support #define symbols that take on a value and C# does not 
support macros. This makes it hard to create an elegant solution for both 
single and double precision. Any suggestions will be welcome on this issue.

Original comment by Jorgy...@gmail.com on 14 Feb 2011 at 8:04

GoogleCodeExporter commented 8 years ago
I added Perp and PerpDot methods to the Vector2 structure in r41.

Original comment by Jorgy...@gmail.com on 15 Feb 2011 at 1:13