Vector

Vector Struct

The Vector class represents a 3 dimensional vector.

Syntax

public struct Vector

Remarks

 

Requirements

Namespace: Sansar
Assembly: Sansar.Script (in Sansar.Script.dll)
Assembly Versions: 1.0.0.0

Members

See Also: Inherited members from ValueType.

Public Constructors

  Creates a new vector with the supplied values.
  Creates a new vector with all values set to the given value.
  Creates a new vector with the supplied values.

Public Fields

static readonly
Back Vector . The default world back vector.
static readonly
Down Vector . The default world down vector.
static readonly
Forward Vector . The default world forward vector.
static readonly
Left Vector . The default world left vector.
static readonly
One Vector . A vector with all components 1.
static readonly
Right Vector . The default world right vector.
static readonly
Up Vector . The default world up vector.
static readonly
Zero Vector . A vector with all components 0.

Public Properties

default property
 
Item (int) float . Allows getting coordinates by index.
  W float . The W coordinate of the vector.
  X float . The X coordinate of the vector.
  Y float . The Y coordinate of the vector.
  Z float . The Z coordinate of the vector.

Public Methods

  AngleTo (ref Vector) : float
Returns the angle in radians between this vector and the given vector.
  Cross (ref Vector) : Vector
Calculates the cross product of 2 3D vectors.
  Dot (ref Vector) : float
Performs a scalar or dot product.
  Length () : float
Calculates the magnitude of this vector.
  LengthSquared () : float
Calculates the magnitude of this vector squared.
  Lerp (ref Vector, float) : Vector
Performs a linear interpolation between two vectors.
  Normalized () : Vector
Returns a vector with the same orientation and unit length.
static
Parse (string) : Vector
Parse a Vector from a string.
  Rotate (ref Quaternion) : Vector
Returns a new vector which is this vector rotated by the given quaternion.
override
ToString () : string
Generates a string representation of the vector.
  ToString (string) : string
Generates a string representation of the vector.
  ToString4 (string) : string
Generates a string representation of the vector, including the W parameter.
static
TryParse (string, out Vector) : bool
Attempt to parse a Vector from a string

Public Operators

static
Addition (Vector, Vector) Performs vector addition.
static
Multiply (Vector, float) Performs a vector scalar multiplication.
static
Subtraction (Vector, Vector) Performs vector subtraction.
static
Conversion to Sansar.Vector (Implicit) Converts a Mono.Simd.Vector4f to a vector.
static
Conversion to Mono.Simd.Vector4f (Implicit) Converts a vector to a Mono.Simd.Vector4f

Member Details

Vector Constructor

Creates a new vector with the supplied values.

Syntax

public Vector (Mono.Simd.Vector4f v)

Parameters

v
Initializes the vector from a Mono.Simd.Vector4f. W should be 0 and is assumed to be 0 for most operations.

Remarks

 

Requirements

Namespace: Sansar
Assembly: Sansar.Script (in Sansar.Script.dll)
Assembly Versions: 1.0.0.0

Vector Constructor

Creates a new vector with all values set to the given value.

Syntax

public Vector (float all)

Parameters

all
The value for all coordinates.

Remarks

W will be set to 0.

Requirements

Namespace: Sansar
Assembly: Sansar.Script (in Sansar.Script.dll)
Assembly Versions: 1.0.0.0

Vector Constructor

Creates a new vector with the supplied values.

Syntax

public Vector (float x, float y, float z, float w)

Parameters

x
The x coordinate.
y
The y coordinate.
z
The z coordinate.
w
The w coordinate. W defaults to 0 and is assumed to be 0 for most operations.

Remarks

 

Requirements

Namespace: Sansar
Assembly: Sansar.Script (in Sansar.Script.dll)
Assembly Versions: 1.0.0.0

AngleTo Method

Returns the angle in radians between this vector and the given vector.

Syntax

public float AngleTo (ref Vector b)

Parameters

b
The angle to compare.

Returns

The smallest angle in radians between the two vectors.

Remarks

 

Requirements

Namespace: Sansar
Assembly: Sansar.Script (in Sansar.Script.dll)
Assembly Versions: 1.0.0.0

Back Field

The default world back vector.

Syntax

public static readonly Vector Back

Remarks

 

Requirements

Namespace: Sansar
Assembly: Sansar.Script (in Sansar.Script.dll)
Assembly Versions: 1.0.0.0

Cross Method

Calculates the cross product of 2 3D vectors.

Syntax

public Vector Cross (ref Vector b)

Parameters

b
The second vector.

Returns

a X b

Remarks

 

Requirements

Namespace: Sansar
Assembly: Sansar.Script (in Sansar.Script.dll)
Assembly Versions: 1.0.0.0

Dot Method

Performs a scalar or dot product.

Syntax

public float Dot (ref Vector b)

Parameters

b
The second vector.

Returns

Returns X*b.X+Y*b.Y+Z*b.Z+W*b.W

Remarks

 

Requirements

Namespace: Sansar
Assembly: Sansar.Script (in Sansar.Script.dll)
Assembly Versions: 1.0.0.0

Down Field

The default world down vector.

Syntax

public static readonly Vector Down

Remarks

 

Requirements

Namespace: Sansar
Assembly: Sansar.Script (in Sansar.Script.dll)
Assembly Versions: 1.0.0.0

Forward Field

The default world forward vector.

Syntax

public static readonly Vector Forward

Remarks

 

Requirements

Namespace: Sansar
Assembly: Sansar.Script (in Sansar.Script.dll)
Assembly Versions: 1.0.0.0

Item Property

Allows getting coordinates by index.

Syntax

This is the default property for this class.

public float this [int index] { get; set; }

Parameters

index
0=>X, 1=>Y, 2=>Z, 3=>W

Value

Remarks

 

Requirements

Namespace: Sansar
Assembly: Sansar.Script (in Sansar.Script.dll)
Assembly Versions: 1.0.0.0

Left Field

The default world left vector.

Syntax

public static readonly Vector Left

Remarks

 

Requirements

Namespace: Sansar
Assembly: Sansar.Script (in Sansar.Script.dll)
Assembly Versions: 1.0.0.0

Length Method

Calculates the magnitude of this vector.

Syntax

public float Length ()

Returns

The magnitude of the vector.

Remarks

 

Requirements

Namespace: Sansar
Assembly: Sansar.Script (in Sansar.Script.dll)
Assembly Versions: 1.0.0.0

LengthSquared Method

Calculates the magnitude of this vector squared.

Syntax

public float LengthSquared ()

Returns

The magnitude of the vector squared.

Remarks

 

Requirements

Namespace: Sansar
Assembly: Sansar.Script (in Sansar.Script.dll)
Assembly Versions: 1.0.0.0

Lerp Method

Performs a linear interpolation between two vectors.

Syntax

public Vector Lerp (ref Vector b, float amount)

Parameters

b
The second vector.
amount
Value from [0..1] indicating the weight for the second vector.

Returns

A vector that is linearly interpolated between the two sources.

Remarks

a + (b-a) * amount.

Requirements

Namespace: Sansar
Assembly: Sansar.Script (in Sansar.Script.dll)
Assembly Versions: 1.0.0.0

Normalized Method

Returns a vector with the same orientation and unit length.

Syntax

public Vector Normalized ()

Returns

A vector with the same orientation and unit length.

Remarks

 

Requirements

Namespace: Sansar
Assembly: Sansar.Script (in Sansar.Script.dll)
Assembly Versions: 1.0.0.0

One Field

A vector with all components 1.

Syntax

public static readonly Vector One

Remarks

 

Requirements

Namespace: Sansar
Assembly: Sansar.Script (in Sansar.Script.dll)
Assembly Versions: 1.0.0.0

op_Addition Method

Performs vector addition.

Syntax

public static Vector operator+ (Vector a, Vector b)

Parameters

a
The first Vector.
b
The second Vector.

Returns

A new vector that is the sum of the arguments.

Remarks

 

Requirements

Namespace: Sansar
Assembly: Sansar.Script (in Sansar.Script.dll)
Assembly Versions: 1.0.0.0

Conversion Method

Converts a Mono.Simd.Vector4f to a vector.

Syntax

public static implicit operator Vector (Mono.Simd.Vector4f v)

Parameters

v
The vector to convert

Returns

Remarks

 

Requirements

Namespace: Sansar
Assembly: Sansar.Script (in Sansar.Script.dll)
Assembly Versions: 1.0.0.0

Conversion Method

Converts a vector to a Mono.Simd.Vector4f

Syntax

public static implicit operator Mono.Simd.Vector4f (Vector v)

Parameters

v
The vector to convert

Returns

Remarks

 

Requirements

Namespace: Sansar
Assembly: Sansar.Script (in Sansar.Script.dll)
Assembly Versions: 1.0.0.0

op_Multiply Method

Performs a vector scalar multiplication.

Syntax

public static Vector operator* (Vector a, float b)

Parameters

a
The vector.
b
The scalar.

Returns

Returns a new vector with value [a.X*b, a.Y*b, a.Z*b, a.W*b]

Remarks

 

Requirements

Namespace: Sansar
Assembly: Sansar.Script (in Sansar.Script.dll)
Assembly Versions: 1.0.0.0

op_Subtraction Method

Performs vector subtraction.

Syntax

public static Vector operator- (Vector a, Vector b)

Parameters

a
The first Vector.
b
The second Vector.

Returns

A new vector that is the difference of the arguments.

Remarks

 

Requirements

Namespace: Sansar
Assembly: Sansar.Script (in Sansar.Script.dll)
Assembly Versions: 1.0.0.0

Parse Method

Parse a Vector from a string.

Syntax

public static Vector Parse (string vectorString)

Parameters

vectorString
A string of the format <X,Y,Z> or <X,Y,Z,W>

Returns

The Vector parsed from the string.

Exceptions

Type Reason
ArgumentException If vectorString is null.
FormatException If the string is not a valid vector or its components are not valid floats.

Remarks

 

Example

C# Example
Vector myVector = Vector.Parse("<1,2.34,5.6>");

Requirements

Namespace: Sansar
Assembly: Sansar.Script (in Sansar.Script.dll)
Assembly Versions: 1.0.0.0

Right Field

The default world right vector.

Syntax

public static readonly Vector Right

Remarks

 

Requirements

Namespace: Sansar
Assembly: Sansar.Script (in Sansar.Script.dll)
Assembly Versions: 1.0.0.0

Rotate Method

Returns a new vector which is this vector rotated by the given quaternion.

Syntax

public Vector Rotate (ref Quaternion q)

Parameters

q
The quaternion rotation.

Returns

Remarks

 

Requirements

Namespace: Sansar
Assembly: Sansar.Script (in Sansar.Script.dll)
Assembly Versions: 1.0.0.0

ToString Method

Generates a string representation of the vector.

Syntax

public override string ToString ()

Returns

The vector as a string.

Remarks

 

Requirements

Namespace: Sansar
Assembly: Sansar.Script (in Sansar.Script.dll)
Assembly Versions: 1.0.0.0

ToString Method

Generates a string representation of the vector.

Syntax

public string ToString (string format)

Parameters

format
Format to use for each of the coordinates.

Returns

The vector as a string.

Remarks

 

Requirements

Namespace: Sansar
Assembly: Sansar.Script (in Sansar.Script.dll)
Assembly Versions: 1.0.0.0

ToString4 Method

Generates a string representation of the vector, including the W parameter.

Syntax

public string ToString4 (string format)

Parameters

format
Format to use for each of the coordinates.

Returns

The vector as a string.

Remarks

 

Requirements

Namespace: Sansar
Assembly: Sansar.Script (in Sansar.Script.dll)
Assembly Versions: 1.0.0.0

TryParse Method

Attempt to parse a Vector from a string

Syntax

public static bool TryParse (string vectorString, out Vector vector)

Parameters

vectorString
A string of the format <X,Y,Z> or <X,Y,Z,W>
vector
The vector that will be set if vectorString represents a valid vector.

Returns

True if successfully parsed a quaternion, false if not.

Remarks

 

Example

C# Example
Vector myVector;
            if (Vector.Parse("<1,2.34,5.6>", out myVector)
            {
                // myVector is set
            }

Requirements

Namespace: Sansar
Assembly: Sansar.Script (in Sansar.Script.dll)
Assembly Versions: 1.0.0.0

Up Field

The default world up vector.

Syntax

public static readonly Vector Up

Remarks

 

Requirements

Namespace: Sansar
Assembly: Sansar.Script (in Sansar.Script.dll)
Assembly Versions: 1.0.0.0

W Property

The W coordinate of the vector.

Syntax

public float W { get; set; }

Value

Remarks

W should be 0 and is assumed to be 0 for most operations.

Requirements

Namespace: Sansar
Assembly: Sansar.Script (in Sansar.Script.dll)
Assembly Versions: 1.0.0.0

X Property

The X coordinate of the vector.

Syntax

public float X { get; set; }

Value

Remarks

 

Requirements

Namespace: Sansar
Assembly: Sansar.Script (in Sansar.Script.dll)
Assembly Versions: 1.0.0.0

Y Property

The Y coordinate of the vector.

Syntax

public float Y { get; set; }

Value

Remarks

 

Requirements

Namespace: Sansar
Assembly: Sansar.Script (in Sansar.Script.dll)
Assembly Versions: 1.0.0.0

Z Property

The Z coordinate of the vector.

Syntax

public float Z { get; set; }

Value

Remarks

 

Requirements

Namespace: Sansar
Assembly: Sansar.Script (in Sansar.Script.dll)
Assembly Versions: 1.0.0.0

Zero Field

A vector with all components 0.

Syntax

public static readonly Vector Zero

Remarks

 

Requirements

Namespace: Sansar
Assembly: Sansar.Script (in Sansar.Script.dll)
Assembly Versions: 1.0.0.0


Was this article helpful?
0 out of 0 found this helpful
Have more questions? Submit a request

0 Comments

Article is closed for comments.