Project

General

Profile

Feature #10074

[PATCH] generalize Vector#cross_product

Added by gogotanaka (Kazuki Tanaka) almost 6 years ago. Updated over 5 years ago.

Status:
Closed
Priority:
Normal
Target version:
[ruby-core:63860]

Description

Usually We use cross_product in only 3 dimensions.

Sometimes we want to handle cross_product in n-dimensions.

But I recognize Ruby should be not for mathematician but rubyist.

Ruby doesn't need too academic method.

So If you think it is too academic you can ignore my patches.


Files

generalize_Vector#cross_product.patch (1.71 KB) generalize_Vector#cross_product.patch gogotanaka (Kazuki Tanaka), 07/19/2014 07:46 AM

Updated by gogotanaka (Kazuki Tanaka) almost 6 years ago

Before

 Vector[1, 0, 0].cross_product Vector[0, 1, 0]
=> Vector[0, 0, 1]

Vector[1, 2].cross_product
=> ArgumentError: wrong number of arguments (0 for 1)

 Vector[3, 5, 2, 1].cross_product(Vector[4, 3, 1, 8], Vector[2, 9, 4, 3])
=> ArgumentError: wrong number of arguments (0 for 1)

After

 Vector[1, 0, 0].cross_product Vector[0, 1, 0]
=> Vector[0, 0, 1]

Vector[1, 2].cross_product
=> Vector[2, -1]

 Vector[3, 5, 2, 1].cross_product(Vector[4, 3, 1, 8], Vector[2, 9, 4, 3])
=> Vector[-16, 65, -139, 1]

This patch needs https://bugs.ruby-lang.org/issues/10072 and https://bugs.ruby-lang.org/issues/10073

gogo.

Updated by hsbt (Hiroshi SHIBATA) almost 6 years ago

  • Category set to lib
  • Status changed from Open to Assigned
  • Assignee set to marcandre (Marc-Andre Lafortune)
  • Target version set to 2.2.0

Updated by marcandre (Marc-Andre Lafortune) over 5 years ago

I committed this change, with a couple of changes.

In particular, the sign was wrong for even dimensions. I changed it so we now have, for any n:

first, *middle, last = Matrix.identity(n).column_vectors
first.cross(*middle) == last

Thanks for this feature request!

Updated by marcandre (Marc-Andre Lafortune) over 5 years ago

  • Status changed from Assigned to Closed

Updated by gogotanaka (Kazuki Tanaka) over 5 years ago

@Marc-Andre Lafortune

I'm really appreciate your help.
And your changes totally makes sense.

Thanks.

Also available in: Atom PDF