help-octave
[Top][All Lists]

## Re: How can I tell if a function (rot2q.m) can be vectorized

 From: Kai Torben Ohlhus Subject: Re: How can I tell if a function (rot2q.m) can be vectorized Date: Wed, 20 Feb 2019 09:57:50 +0100

On Fri, Feb 15, 2019 at 1:15 PM RT <address@hidden> wrote:
Attached rot2q.m file in question

On Fri, Feb 15, 2019 at 7:12 AM RT <address@hidden> wrote:
How can I tell if a function (rot2q.m) can be vectorized?

This is my logic:
1) Convert multiple xyz points in array to quaternions using the function rot2q
2) Do calculations on multiple points from array in quaternions using the function quaternion
3) Convert quaternion array data back to xyz points using the function q2rot
4) Plot new xyz points using the function scatter3

The error I get is

"error: rot2q: first argument 'axis' must be a length three vector
error: called from
rot2q at line 74 column 5
test_quaternion_array_coversion at line 10 column 21"

Does the quaternion functions not allow vectorization?  And if not how can I change the functions to support this?

Some test code is below I've also attached the rot2q.m file :
I'm testing using Octave 5.0.91 on Ubuntu 18.04 64bit

clear all
xyz_angle=[0  1  0  1.570796326794897;0.5  1  0  1.570796326794897]
pt_xyz_angle_to_quat=rot2q ([xyz_angle(:,1),xyz_angle(:,2),xyz_angle(:,3)], xyz_angle(:,4))

--

--
--
|======================================================|
|https://stillpointx.wordpress.com/research/modulated-plasma/
|======================================================|
"Knowledge may be the Key"
"But wisdom unlocks the door"
"Absolute Power demands absolutely nothing"

As the old maxim has it, you need find only one white crow to disprove the rule that all crows are black

"The bourgeois today burns as heretics and hangs as criminals those to whom he erects monuments tomorrow" ('Steppenwolf')

"There are two modes of being those in bliss and those seeking bliss,
may each step you take and each thought you make be made in a mindful and blissful state."
|======================================================|

By looking at your attached function rot2q.m, there is a check in line 73  `isvector (vv)` which fails for your 2x3 matrix input `[xyz_angle(:,1),xyz_angle(:,2),xyz_angle(:,3)]`.

This function seems not intended to handle multiple inputs as you desire.  On the other hand the quaternion constructor can handle multiple inputs.

I attached a rot2q.m version that should come close to what you are looking for.  Please improve it, and when it works for you please file a bug report to apply this improved function to the quaternion package.

Best,
Kai

rot2q.m
Description: Text Data