# Understanding/converting vector maths code

Discussion in 'Math' started by AlbertHall, Jan 30, 2019.

1. ### AlbertHall Thread Starter AAC Fanatic!

Jun 4, 2014
7,082
1,697
I have the following code from a 'C' program:
Code (C):
1.
2.
3.   public class Vector
4.   {
5.   public double X;
6.   public double Y;
7.
8. public double Cross(Vector v)
9.   {
10.   return X * v.Y - Y * v.X;
11.   }
12. }
13.
Although this is called 'Cross' it is not, as far as I can tell, a cross product.
It returns a scalar quantity.

Can someone please tell what this is called and what the result represents, please?

Sep 9, 2010
15,558
5,763
3. ### Papabravo Expert

Feb 24, 2006
11,868
2,523
It looks like the z-component of the Cross Product. More correctly it is the magnitude of the z-component of the Cross Product. The Corss Product of two vectors is a vector that is perpendicular to both of the original vectors. It cannot be represented in 2-dimensional space.

bogosort likes this.
4. ### bogosort Active Member

Sep 24, 2011
238
132
That code is definitely not C, nor is it very meaningful on its own. But if I had to guess, I'd say that it is calculating the determinant of a 2x2 matrix comprised of two row vectors U = [u_x u_y] and V = [v_x v_y]:

$det( \begin{bmatrix}u_x u_y \\ v_x v_y\end{bmatrix} ) = u_x v_y - u_y v_x$

This can arguably be called a 2D cross product, which is indeed a scalar, but it would have been far less confusing if they had called it det() instead of Cross(). (And they should have used uppercase for vector names, and lowercase for component names.)

5. ### AlbertHall Thread Starter AAC Fanatic!

Jun 4, 2014
7,082
1,697
Yes, thank you. Dot product or scalar product.

That may be because I have chopped out the bit I didn't understand from the whole thing which does go on a bit.
In my searches I did come across a comment that 'object oriented code is a way of making a simple program look big and complicated'.

bogosort likes this.