1. Products
  2.   3D
  3.   Swift
  4.   VectorMath
 
  

Free Swift Library for 2D, 3D Vector & Matrix Functions

Open Source Swift Library for 2D, 3D Vector & Matrix Functions. It allows to Perform Vector Operations, Matrix Transformations & so on.

What is VectorMath Library?

Many tasks in math and computing rely on vector operations, such as in graphics, physics, and machine learning. With the rise of Swift as a flexible and effective programming language, there’s a growing demand for strong libraries that handle vector math well. Meet VectorMath – a robust Swift library crafted to simplify vector computations and equip you with smooth and user-friendly features. It is a powerful Open Source Swift library that simplifies working with vectors, matrices, and quaternions. Developed with performance and ease of use in mind, the library offers a wide range of functionalities for both 2D and 3D applications.

The VectorMath library offers tools and structures to help you with vector operations like adding, subtracting, multiplying, finding dot and cross products, normalizing, and more. It smoothly operates on different Apple platforms, ensuring that your vector calculations stay consistent. This compatibility across platforms is important for game developers who want their games to work well on different devices. It provides a simple and efficient API for software developers to handle advanced vector tasks without compromising speed or clarity. Moreover, the library comes with thorough documentation, providing in-depth descriptions and sample uses for every feature. Whether you’re an experienced game developer or new to Swift, using this library in your projects can help you save time and energy. Feel free to dive into the realm of vector mathematics with VectorMath.

Previous Next

Getting Started with VectorMath

The easiest way to install VectorMath stable release is using CocoaPods. Please use the following command for a smooth installation.

Install VectorMath Library using CocoaPods

pod 'VectorMath', '~> 0.4'
pod install
 

Install VectorMath via GitHub

git clone https://github.com/nicklockwood/VectorMath.git 

You can download the compiled shared library from Github repository.

Perform Vector Operations in Swift Apps

The open source VectorMath library allows software developers to perform various types of Vector operations inside their Mac and iOS Swift applications. The library provides a comprehensive set of vector operations, including addition, subtraction, scaling, dot product, cross product, and normalization. These operations are optimized to ensure fast and efficient calculations. The following example shows how software developers can creating vectors, matrices, or quaternions with just a few lines of code.

How to Create Vectors and Perform Operations on It via Swift API?

import VectorMath

let vectorA = Vector3(x: 1.0, y: 2.0, z: 3.0)
let vectorB = Vector3(x: 4.0, y: 5.0, z: 6.0)

let sumVector = vectorA + vectorB
let dotProduct = vectorA • vectorB
let normalizedVector = vectorA.normalized()

Apply Matrix Transformations via Swift API

Working with matrices is a breeze with VectorMath. The library provides support for transformation matrices, enabling software developers to perform complex transformations with just a couple of lines of Swift code. The library supports various types of transformations, such as translation, rotation, scaling, shearing, projection, and so on. These capabilities prove invaluable when dealing with graphics rendering and 3D modeling tasks. The following example shows how programmers can perform matrices transformations inside their own Swift applications with just a couple of lines of code.

How to Perform Matrix Transformations inside Swift Apps?

let scaleMatrix = Matrix4.scale(x: 2.0, y: 2.0, z: 2.0)
let vector = Vector3(x: 1.0, y: 2.0, z: 3.0)
let scaledVector = scaleMatrix * vector

Quaternion Support via Swift Library

Quaternion operations are essential in 3D rotations and orientation computations. The open source VectorMath library offers a robust quaternion implementation, allowing software developers to perform operations like quaternion multiplication, interpolation, and conversion to and from other representations. The creators of library aimed to design an intuitive and Swifty API. By following Swift conventions and paradigms, the library feels like a natural extension of the language, reducing the learning curve for developers.