Questions tagged [nalgebra]

nalgebra is a linear algebra library written for Rust

nalgebra is a linear algebra library written for Rust targeting:

General-purpose linear algebra (still lacks a lot of features…)
Real-time computer graphics.
Real-time computer physics.
43 questions
0
votes
1 answer

How does the Rust nalgebra crate implement broadcast operations on matrix?

I'm learning to use the nalgebra library and the problem I'm having is: how to add, subtract, multiply, divide a number for each element in a matrix? Say I have a 2x3 matrix which has i32 elements: extern crate nalgebra as na; use na::*; fn main()…
Mike
  • 35
  • 5
0
votes
0 answers

Wrong number of rows / columns in nalgebra SMatrix generated from iterator

The following code: let m: SMatrix = SMatrix::from_iterator((1..).map(|x| x as f64)); println!("{:?}", m); produces the following output: [[1.0, 2.0], [3.0, 4.0], [5.0, 6.0]] The matrix outputed has 3 rows, and each row has 2 columns.…
rochard4u
  • 629
  • 3
  • 17
0
votes
0 answers

rust nalgebra set a block in matrix to rotation?

I am trying to set the upper left block of a 4X4 matrix to a rotation matrix. I have tried different flavours of: let mut mat = Mat4::identity(); mat.set_column(3, &Vec4::new(trans.x, trans.y, trans.z, 1.0)); let slice =…
Makogan
  • 8,208
  • 7
  • 44
  • 112
0
votes
1 answer

Initialize a matrix in Rust using the "nalgebra" crate

How can I initialize a 3D matrix in Rust given the number number of component in x, y, z and a given nuber for intialization (let's say 1.0). At the moment I use no librares: let nx: usize = 100; // y-resolution …
Mattia Samiolo
  • 365
  • 2
  • 8
0
votes
1 answer

How do I calculate inner product of two vectors in nalgebra?

From the following let v = OVector::::from_column_slice(&[3_f64, 4_f64]); let x = &v.transpose() * &v; // get the inner product, i.e. I expected x to be a f64 scalar, i.e. x = 25.0. But actually, I can only obtain x as…
xc wang
  • 318
  • 1
  • 3
  • 14
0
votes
1 answer

Rust: nalgebra transpose

I've started to practice rust. I've run the program and got: VecStorage { data: [1.0, 88.0, 87.0, 1.0, 70.0, 77.0, 1.0, 80.0, 79.0, 1.0, 82.0, 85.0, 1.0, 90.0, 97.0, 1.0, 100.0, 98.0], nrows: Dynamic { value: 6 }, ncols: Dynamic { value: 3 }…
Guy-Arieli
  • 33
  • 7
0
votes
1 answer

nalgebra apply function to every element of a vector

sorry if this is a noob question but is it posible to apply a function to every element in a nalgebra vector? if I for example have a vector like this: type Vector2x1 = SVector; let vector = Vector2x1::new(2.0, 2.0); how can I apply a…
0
votes
1 answer

Rust nalgebra inverse matrix

Does anyone no a simple way to get the inverse of a matrix using the Rust nalgebra::Matrix ? I'm trying to do this the same way as with the C++ Eigen library but clearly not working. #cargo.toml [dependencies] nalgebra = "0.30" #main.rs let mut m =…
sbeskur
  • 2,260
  • 23
  • 23
0
votes
0 answers

nalgebra OVector vs SVector?

What's the difference between OVector and SVector in nalgebra? Why is there no SPoint?
user357269
  • 1,835
  • 14
  • 40
0
votes
0 answers

Is it possible to expose nalgebra matrix types to python via pyo3 in rust

I'm able to expose simple functions written in Rust to python using pyo3 but can see no way to expose complex "eigen" / matrix types. Does anyone know if this is possible? lib.rs extern crate nalgebra as na; use pyo3::prelude::*; use…
sbeskur
  • 2,260
  • 23
  • 23
0
votes
1 answer

How to average two points in nalgebra?

I have a triangle ABC, and I want to generate triangle DEF. Triangle DEF is created using the centre of all edges of ABC. Nalgebra doesn't seem to allow me to do add points together, only vectors. use nalgebra::Point2; fn get_def(a: Point2,…
Jeroen
  • 15,257
  • 12
  • 59
  • 102
0
votes
0 answers

How do I rotate an object so that it's always facing the mouse position?

I'm using ggez to make a game with some friends, and I'm trying to have our character rotate to face the pointer at all times. I know so far that I need to get an angle value (f32) in radians, and I think I can use atan2 to get this (?) However, I…
0
votes
2 answers

Is there a good way to do an overlapping copy in ndarray in rust?

Here's what I tried use ndarray::{arr2, s}; let mut a = arr2(&[[1, 2, 3], [4, 5, 6]]); let b = arr2(&[[2, 3, 3], [5, 6, 6]]); a.slice_mut(s![.., ..2]).assign(&a.slice_mut(s![.., 1..])); which obviously fails…
Antony Hatchkins
  • 31,947
  • 10
  • 111
  • 111
1 2
3