Not Yet Answered # What does a Vector3 and Quaternion look like in code?

gusano79 247 ddanbe 2,451

0

I'm looking for what exactly is a Vector3 (or any Vector for that matter) and also what a Quaternion is in code? What are the variables types? Should you have multiple classes for each type?

Depends on the language you're using, and even then, there are multiple ways to represent vectors and quaternions.

Vectors in **R3** can be simple structures with *x*, *y*, and *z* members, or you can use an array-like member to hold those values instead. You'll need arrays (or equivalent) to represent generic vectors in **Rn** though. If you're going to be working with matrices, you might also consider using a *1xn* or *nx1* matrix for your vectors.

The actual member type will be something "close enough" to a real number. For practical purposes, this is usually a single- or double-precision floating point value, unless you're doing something special, which is an entirely different conversation.

Then there are vector operations--some are only defined for vectors of certain sizes, and others, while they can be written generically for any size vector, have alternate implementations that are smaller and/or faster for certain sizes. Depending on your language, you may be able to take advantage of inheritance and/or templates to avoid writing duplicate code.

The quaternions (denoted **H**) are equivalent to vectors in **R4**, just with special operations.

0

As you don't exactly state the exact programming language you're working in, you will find on this Rosetta site some code for quaternions.

**Isn't it about time forums rewarded their contributors?**

Contribute to this discussion and earn rewards points that can be cashed out for dollars.

This article has been dead for over six months. Start a new discussion instead.

Recommended Articles

I'm trying to figure out how do i print a distinct enum value by using a conditional statement in my construction of array.

I have a enum declaration

`enum Animal {Rat, Ox, Tiger, Rabbit, Dragon, Snake, Horse, Sheep, Monkey, Rooster, Dog, Pig};`

And i construct my array using a voidptr ...

I need to comput and display the sum and average of the cubes of the even natural numbers between 2 and n. Where n is entered by the user. Im stuck on how to average the sum of the cubes. Help Please. This is what I have so far.

`def ...`

I'm new to python, for my project I need to send mail from python.. I'm getting the following error can someone please help me how to get out of it..

```
Python 3.4.3 (v3.4.3:9b73f1c3e601, Feb 24 2015, 22:43:06) [MSC v.1600 32 bit (Intel)] on win32
Type "copyright", "credits" or "license()" for ...
```