BlitzMax

BlitzMax

  • Downloads
  • Docs
  • API
  • Resources
  • About

›Vector

BlitzMax API

  • Introduction

BRL

    Audio

    • Introduction
    • TChannel
    • TSound

    AudioSample

    • Introduction
    • TAudioSample
    • TAudioSampleLoader

    Bank

    • Introduction
    • TBank

    BankStream

    • Introduction
    • TBankStream

    Base64

    • Introduction
    • TBase64

    Blitz

    • Introduction
    • TArrayBoundsException
    • TBlitzException
    • TNullFunctionException
    • TNullMethodException
    • TNullObjectException
    • TOutOfDataException
    • TRuntimeException
  • BRL.BMPLoader
  • Clipboard

    • Introduction
    • TClipboard
    • TClipboardOpts
    • TWin32ClipboardOpts
    • TX11ClipboardOpts
  • BRL.D3D7Max2D
  • BRL.D3D9Max2D
  • BRL.DirectSoundAudio
  • BRL.EndianStream
  • Event

    • Introduction
    • TEvent
  • BRL.EventQueue
  • BRL.FileSystem
  • BRL.FreeAudioAudio
  • BRL.GLGraphics
  • BRL.GLMax2D
  • BRL.GNet
  • BRL.Graphics
  • BRL.Hook
  • IO

    • Introduction
    • MaxIO
  • BRL.JPGLoader
  • BRL.KeyCodes
  • LinkedList

    • Introduction
    • TList
    • TListEnum
    • TLink

    Map

    • Introduction
    • TMap
    • TIntMap
    • TIntKey
    • TPtrMap
    • TPtrKey
    • TStringMap
  • BRL.Math
  • Matrix

    • Introduction
    • SMat2D
    • SMat2F
    • SMat2I
    • SMat3D
    • SMat3F
    • SMat3I
    • SMat4D
    • SMat4F
    • SMat4I

    Max2D

    • Introduction
    • TImage

    MaxLua

    • Introduction
    • TLuaClass
    • TLuaObject
  • BRL.OGGLoader
  • BRL.OpenALAudio
  • ObjectList

    • Introduction
    • TObjectList
    • TObjectListEnumerator
    • TObjectListReverseEnumerator

    Pixmap

    • Introduction
    • TPixmap
    • TPixmapLoader
  • BRL.PNGLoader
  • BRL.PolledInput
  • Quaternion

    • Introduction
    • SQuatD
    • SQuatF
    • SQuatI
  • BRL.RamStream
  • Random

    • Introduction
    • TRandom

    Reflection

    • Introduction
    • TTypeId
    • TMember
    • TConstant
    • TField
    • TGlobal
    • TFunction
    • TMethod
  • BRL.Retro
  • BRL.Socket
  • BRL.SocketStream
  • BRL.StandardIO
  • Stream

    • Introduction
    • TCStream
    • TIO
    • TStream
    • TStreamException
    • TStreamFactory
    • TStreamReadException
    • TStreamWrapper
    • TStreamWriteException

    StringBuilder

    • Introduction
    • TStringBuilder
    • TSplitBuffer
  • BRL.System
  • BRL.SystemDefault
  • BRL.TextStream
  • BRL.TGALoader
  • ThreadPool

    • Introduction
    • TRunnable
    • TThreadPoolExecutor

    Threads

    • Introduction
    • TThread
    • TThreadData
    • TMutex
    • TSemaphore
    • TCondVar

    Timer

    • Introduction
    • TChrono
  • BRL.TimerDefault
  • Vector

    • Introduction
    • SVec2D
    • SVec2F
    • SVec2I
    • SVec3D
    • SVec3F
    • SVec3I
    • SVec4D
    • SVec4F
    • SVec4I

    Volumes

    • Introduction
    • TVolume
  • BRL.WAVLoader

Text

    CSV

    • Introduction
    • TCsvParser
    • TCsvHeader
    • TCsvRow
    • TCsvOptions
    • SCsvColumn

    Format

    • Introduction
    • TFormatter

    Ini

    • Introduction
    • TIni
    • TIniProperty
    • TIniSection

    JConv

    • Introduction
    • TJConv
    • TJConvBuilder
    • TJConvSerializer

    Json

    • Introduction
    • TJSON
    • TJSONObject
    • TJSONString
    • TJSONInteger
    • TJSONReal
    • TJSONBool
    • TJSONArray
    • TJSONNull
    • TJSONError
    • TJSONNumber

    Regex

    • Introduction
    • TRegEx
    • TRegExMatch
    • TRegExOptions
    • TRegExException

    TOML

    • Introduction
    • ETomlNodeType
    • TToml
    • ITomlNode
    • STomlDate
    • STomlDateTime
    • STomlTime
    • TTomlArray
    • TTomlInteger
    • TTomlString
    • TTomlTable
    • TTomlBoolean

    Xml

    • Introduction
    • TxmlDoc
    • TxmlNode
    • TxmlAttribute

MaxGUI

  • MaxGUI.MaxGUI
  • MaxGUI.Drivers
  • MaxGUI.Localization
  • MaxGUI.ProxyGadgets
  • MaxGUI.CocoaMaxGUI
  • MaxGUI.Win32MaxGUIEx

PUB

  • Pub.FreeJoy
  • Pub.FreeProcess
  • Pub.Glad
  • Pub.Glew
  • Joystick

    • Introduction
    • TJoystickDriver
  • Pub.Lua
  • Pub.OpenAL
  • Pub.OpenGLES
  • Pub.xmmintrin
  • Pub.ZLib

Crypto

    Digest

    • Introduction
    • TMessageDigest
    • TDigestRegister
    • TNoSuchAlgorithmException

    Cipher

    • Introduction
    • TCipher
    • TCipherMode
    • Crypto.AESCipher
    • Crypto.AnubisCipher
    • Crypto.BlowfishCipher
    • Crypto.CamelliaCipher
    • Crypto.Cast5Cipher
    • Crypto.DESCipher
    • Crypto.IdeaCipher
    • Crypto.KasumiCipher
    • Crypto.KhazadCipher
    • Crypto.KSeedCipher
    • Crypto.NoekeonCipher
    • Crypto.SerpentCipher
    • Crypto.SkipjackCipher
    • Crypto.TwofishCipher
    • Crypto.XTeaCipher

    CBCMode

    • Introduction
    • TCBCCipherMode

    CFBMode

    • Introduction
    • TCFBCipherMode

    CTRMode

    • Introduction
    • TCTRCipherMode

    ECBMode

    • Introduction
    • TECBCipherMode

    F8Mode

    • Introduction
    • TF8CipherMode

    LRWMode

    • Introduction
    • TLRWCipherMode

    OFBMode

    • Introduction
    • TOFBCipherMode

    XTSMode

    • Introduction
    • TXTSCipherMode

    Blake2BDigest

    • Introduction
    • TBlake2B_512
    • TBlake2B_384
    • TBlake2B_256
    • TBlake2B_160

    CRC32

    • Introduction
    • TCRC32

    MD5Digest

    • Introduction
    • TMD5

    Ripemd320Digest

    • Introduction
    • TRipemd320

    Ripemd356Digest

    • Introduction
    • TRipemd256

    Ripemd160Digest

    • Introduction
    • TRipemd160

    Ripemd128Digest

    • Introduction
    • TRipemd128

    SHA1Digest

    • Introduction
    • TSHA1

    SHA256Digest

    • Introduction
    • TSHA256

    SHA512Digest

    • Introduction
    • TSHA512

    SHA3Digest

    • Introduction
    • TSHA3_512
    • TSHA3_384
    • TSHA3_256
    • TSHA3_224

    TigerDigest

    • Introduction
    • TTiger

    WhirlpoolDigest

    • Introduction
    • TWhirlpool

    Crypto

    • Introduction
    • TCryptoRandom
    • TCryptoSecretBox
    • TCryptoHash
    • TCryptoSign
    • TCryptoKeyExchange
    • TCryptoKey
    • TCryptoHashKey
    • TCryptoSecretBoxKey
    • TCryptoSignature
    • TCryptoExchangeKeyPair
    • TCryptoSessionKeyPair
    • TCryptoNPacket
    • TCryptoKK1Packet
    • TCryptoKK2Packet
    • TCryptoXX1Packet
    • TCryptoXX2Packet
    • TCryptoXX3Packet
    • TCryptoExchangeState
    • TCryptoPWHashMasterKey
    • TCryptoPWHashStoredKey
    • TCryptoPasswordHash

SDL

    SDL

    • Introduction
    • TSDLStream

    SDLSystem

    • Introduction
    • TSDLMultiGesture

    SDLVideo

    • Introduction
    • TSDLDisplay
    • TSDLDisplayMode
    • TSDLGLContext
    • TSDLWindow

    SDLRender

    • Introduction
    • TSDLRenderer
    • TSDLTexture

    SDLTimer

    • Introduction
    • TSDLTimer

    SDLHaptic

    • Introduction
    • TSDLHaptic
    • TSDLHapticCondition
    • TSDLHapticConstant
    • TSDLHapticCustom
    • TSDLHapticDirection
    • TSDLHapticEffect
    • TSDLHapticLeftRight
    • TSDLHapticPeriodic
    • TSDLHapticRamp

    SDLSensor

    • Introduction
    • TSDLSensor
  • SDL.SDLFreeAudio
  • SDL.GLSDLMax2D
  • SDL.GL2SDLMax2D
  • SDL.D3D9SDLMax2D
  • SDLVirtualJoystick

    • Introduction
    • TVirtualJoystick

Steam

    SteamSDK

    • Introduction
    • TSteamClient
    • TSteamUtils
    • TSteamUserStats
    • TSteamFriends
    • TSteamUGC
    • ISteamFriendsListener
    • ISteamUGCListener
    • ISteamUserStatsListener
    • ISteamUtilsListener
    • EItemPreviewType
    • EPersonaChange
    • EPersonaState
    • ERemoteStoragePublishedFileVisibility
    • EUGCMatchingUGCType
    • EUGCQuery
    • EUserRestriction
    • EUserUGCList
    • EWorkshopFileType
Edit

SVec2D

A 2-element structure that can be used to represent positions and directions in 2D-space.

Constructors

Method New(x:Double, y:Double)

Creates a new SVec2D from the supplied arguments.


Operators

Method Operator<>:Int(b:SVec2D)

Returns True if b is different.


Method Operator=:Int(b:SVec2D)

Returns True if the vector and b are aproximately equal.


Method Operator+:SVec2D(b:SVec2D)

Adds b to the vector, returning a new vector.

Example

SuperStrict

Framework brl.standardio
Import brl.vector

Local a:SVec2D = New SVec2D(3, 2)
Local b:SVec2D = New SVec2D(-2, 1)

Local c:SVec2D = a + b

Print c.ToString() ' 1, 3


Method Operator-:SVec2D(b:SVec2D)

Subtracts b from the vector, returning a new vector.

Example

SuperStrict

Framework brl.standardio
Import brl.vector

Local a:SVec2D = New SVec2D(12, 2)
Local b:SVec2D = New SVec2D(4, 5)

Local c:SVec2D = a - b

Print c.ToString() ' 8, -3


Method Operator*:SVec2D(b:SVec2D)

Multiplies the vector by b, returning a new vector.

Example

SuperStrict

Framework brl.standardio
Import brl.vector

Local a:SVec2D = New SVec2D(2, 3)
Local b:SVec2D = New SVec2D(5, 6)

Local c:SVec2D = a * b

Print c.ToString() ' 10, 18


Method Operator/:SVec2D(b:SVec2D)

Divides the vector by b, returning a new vector.

Example

SuperStrict

Framework brl.standardio
Import brl.vector

Local a:SVec2D = New SVec2D(10, 18)
Local b:SVec2D = New SVec2D(5, 6)

Local c:SVec2D = a / b

Print c.ToString() ' 2, 3


Method Operator-:SVec2D()

Returns a new vector, negated.

Example

SuperStrict

Framework brl.standardio
Import brl.vector

Local a:SVec2D = New SVec2D(12, 2)

Local b:SVec2D = -a

Print b.ToString() ' -12, -2


Method Operator*:SVec2D(s:Double)

Scales the vector by s, returning a new vector.

Example

SuperStrict

Framework brl.standardio
Import brl.vector

Local m:SVec2D = New SVec2D(7, 3)

Local a:SVec2D = m * 3

Print a.ToString() ' 21, 9


Method Operator/:SVec2D(s:Double)

Divides the vector by s, returning a new vector.

Example

SuperStrict

Framework brl.standardio
Import brl.vector

Local m:SVec2D = New SVec2D(21, 9)

Local a:SVec2D = m / 3

Print a.ToString() ' 7, 3


Method Operator[]:Double(index:Int)

Retrieves the x or y component using [0] or [1] respectively.

Example

SuperStrict

Framework brl.standardio
Import brl.vector

Local a:SVec2D = New SVec2D(6, 4)

Print a[0] + ", " + a[1]


Methods

Method AngleTo:Double(b:SVec2D)

Returns the unsigned angle between this vector and b.

Example

SuperStrict

Framework brl.standardio
Import brl.vector

Local a:SVec2D = New SVec2D(-5, -5)
Local b:SVec2D = New SVec2D(5, 5)


Local c:Double = a.AngleTo(b)

Print c


Method Clamp:SVec2D(minv:SVec2D, maxv:SVec2D)

Returns a vector clamped between the vectors minv and maxv.

Example

SuperStrict

Framework brl.standardio
Import brl.vector

Local a:SVec2D = New SVec2D(0, 0)
Local b:SVec2D = New SVec2D(10, 5)

Local v:SVec2D = New SVec2D(11, -2)


Local c:SVec2D = v.Clamp(a, b)

Print c.ToString() ' 10, 0


Method Min:SVec2D(b:SVec2D)

Returns a vector that is made from the smallest components of the two vectors.

Example

SuperStrict

Framework brl.standardio
Import brl.vector

Local a:SVec2D = New SVec2D(12, 8)
Local b:SVec2D = New SVec2D(10, 16)


Local c:SVec2D = a.Min(b)

Print c.ToString() ' 10, 8


Method Max:SVec2D(b:SVec2D)

Returns a vector that is made from the largest components of the two vectors.

Example

SuperStrict

Framework brl.standardio
Import brl.vector

Local a:SVec2D = New SVec2D(12, 8)
Local b:SVec2D = New SVec2D(10, 16)


Local c:SVec2D = a.Max(b)

Print c.ToString() ' 12, 16


Method Interpolate:SVec2D(b:SVec2D, t:Double)

Linearly interpolates between two vectors.

Interpolates between this vector and b by the interpolant t. This is commonly used to find a point some fraction of the way along a line between two endpoints (e.g. to move an object gradually between those points).

Example

SuperStrict

Framework brl.standardio
Import brl.vector

Local a:SVec2D = New SVec2D(-6, 8)
Local b:SVec2D = New SVec2D(5, 12)

Print a.Interpolate(b, 0).ToString() ' -6, 8
Print a.Interpolate(b, 1).ToString() ' 5, 12
Print a.Interpolate(b, 0.5).ToString() ' -0.5, 10


Method Normal:SVec2D()

Returns a vector with a magnitude of 1.

When normalized, a vector keeps the same direction but its length is 1.0.

Example

SuperStrict

Framework brl.standardio
Import brl.vector

Local a:SVec2D = New SVec2D(10, 0)

Local b:SVec2D = a.Normal()

Print b.ToString() ' 1, 0


Method Dot:Double(b:SVec2D)

Returns the dot product of two vectors.

For normalized vectors Dot returns 1 if they point in exactly the same direction, -1 if they point in completely opposite directions, and a number in between for other cases (e.g. Dot returns zero if vectors are perpendicular).

Example

SuperStrict

Framework brl.standardio
Import brl.vector

Local a:SVec2D = New SVec2D(-6, 8)
Local b:SVec2D = New SVec2D(5, 12)

Local dot:Float = a.Dot(b)

Print dot ' 66


Method Length:Double()

Returns the length of the vector.

Example

SuperStrict

Framework brl.standardio
Import brl.vector

Local a:SVec2D = New SVec2D(3, 4)

Local length:Float = a.Length()

Print length ' 5


Method LengthSquared:Double()

Returns the squared length of the vector.

Calculating the squared length instead of the length is much faster. Often if you are comparing lengths of two vectors you can just compare their squared lengths.

Example

SuperStrict

Framework brl.standardio
Import brl.vector

Local a:SVec2D = New SVec2D(3, 4)

Local length:Double = a.LengthSquared()

Print length ' 25


Method DistanceTo:Double(b:SVec2D)

Returns the distance between the vector And b.


Method DistanceToSquared:Double(b:SVec2D)

Returns the squared distance between the vector and b.


Method Perpendicular:SVec2D()

Returns a vector perpendicular to the vector.


Method Reflect:SVec2D(n:SVec2D)

Returns a vector reflected from the given plane, specified by its normal vector.

Example

SuperStrict

Framework brl.standardio
Import brl.vector

Local a:SVec2D = New SVec2D(5, 0)
Local b:SVec2D = New SVec2D(0, 10)

Local c:SVec2D = a.Reflect(b)

Print c.ToString() ' -5, 0


Method Rotate:SVec2D(angle:Double)

Returns a vector rotated by angle degrees.


Method ToString:String() Override

Returns a String representation of the vector.


← IntroductionSVec2F →
  • Constructors
    • Method New(x:Double, y:Double)
  • Operators
    • Method Operator<>:Int(b:SVec2D)
    • Method Operator=:Int(b:SVec2D)
    • Method Operator+:SVec2D(b:SVec2D)
    • Method Operator-:SVec2D(b:SVec2D)
    • Method Operator*:SVec2D(b:SVec2D)
    • Method Operator/:SVec2D(b:SVec2D)
    • Method Operator-:SVec2D()
    • Method Operator*:SVec2D(s:Double)
    • Method Operator/:SVec2D(s:Double)
    • Method Operator[]:Double(index:Int)
  • Methods
    • Method AngleTo:Double(b:SVec2D)
    • Method Clamp:SVec2D(minv:SVec2D, maxv:SVec2D)
    • Method Min:SVec2D(b:SVec2D)
    • Method Max:SVec2D(b:SVec2D)
    • Method Interpolate:SVec2D(b:SVec2D, t:Double)
    • Method Normal:SVec2D()
    • Method Dot:Double(b:SVec2D)
    • Method Length:Double()
    • Method LengthSquared:Double()
    • Method DistanceTo:Double(b:SVec2D)
    • Method DistanceToSquared:Double(b:SVec2D)
    • Method Perpendicular:SVec2D()
    • Method Reflect:SVec2D(n:SVec2D)
    • Method Rotate:SVec2D(angle:Double)
    • Method ToString:String() Override
BlitzMax
Docs
Getting StartedDownloadsAbout
Community
ResourcesSyntaxBomb Forums
More
GitHubStarChat on Discord
Copyright © 2023 Bruce A Henderson