<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0">
  <channel>
    <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/238691</link>
    <title>MATLAB Central Newsreader - How to create vectors from position data?</title>
    <description>Feed for thread: How to create vectors from position data?</description>
    <language>en-us</language>
    <copyright>&amp;copy;1994-2012 by MathWorks, Inc.</copyright>
    <webmaster>webmaster@mathworks.com</webmaster>
    <generator>MATLAB Central Newsreader</generator>
    <docs>http://blogs.law.harvard.edu/tech/rss</docs>
    <ttl>60</ttl>
    <image>
      <title>MathWorks</title>
      <url>http://www.mathworks.com/images/membrane_icon.gif</url>
    </image>
    <item>
      <pubDate>Wed, 05 Nov 2008 08:15:19 -0500</pubDate>
      <title>How to create vectors from position data?</title>
      <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/238691#609093</link>
      <author>Dai </author>
      <description>Hi everyone&lt;br&gt;
&lt;br&gt;
I have exported three dimensional coordinate data of markers placed along either side of a human spine into a text file. Each marker has three coordinates (x,y,z). I attempted to import the text file into MatLab to create vectors connecting each pair of markers and compute the angle of one vector relative to another but could not work out what functions to use. It would be greatly appreciated if anyone could advise me how to create vectors from coordinate data and compute angles thereafter. &lt;br&gt;
&lt;br&gt;
Thank you in advance&lt;br&gt;
Dai</description>
    </item>
    <item>
      <pubDate>Wed, 05 Nov 2008 12:17:41 -0500</pubDate>
      <title>Re: How to create vectors from position data?</title>
      <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/238691#609127</link>
      <author>Rune Allnor</author>
      <description>On 5 Nov, 09:15, &quot;Dai&quot; &amp;lt;relax2...@hotmail.com&amp;gt; wrote:&lt;br&gt;
&amp;gt; Hi everyone&lt;br&gt;
&amp;gt;&lt;br&gt;
&amp;gt; I have exported three dimensional coordinate data of markers placed along either side of a human spine into a text file. Each marker has three coordinates (x,y,z). I attempted to import the text file into MatLab to create vectors connecting each pair of markers and compute the angle of one vector relative to another but could not work out what functions to use. It would be greatly appreciated if anyone could advise me how to create vectors from coordinate data and compute angles thereafter.&lt;br&gt;
&lt;br&gt;
How to create the vector data depends on how you imported&lt;br&gt;
the (x,y,z) data. If you loaded plain text files, the vectors&lt;br&gt;
are already there, as rows or columns in the matrix you loaded.&lt;br&gt;
If the data were loaded as objects or cell arrays, you need to&lt;br&gt;
consult the dcumentation of the format you use.&lt;br&gt;
&lt;br&gt;
As for the angles between vectors, you might want to use the&lt;br&gt;
dot and cross products, see the functions DOT and CROSS.&lt;br&gt;
&lt;br&gt;
Rune</description>
    </item>
    <item>
      <pubDate>Wed, 05 Nov 2008 15:34:09 -0500</pubDate>
      <title>Re: How to create vectors from position data?</title>
      <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/238691#609178</link>
      <author>cpp.matlab@gmail.com</author>
      <description>This example will derive the smallest angle in degrees between two&lt;br&gt;
lines in 3D space. The coordinates are in float form in x,y,z format.&lt;br&gt;
For 2D lines, just set the z value to zero. E.g x,y,z = (23,14,0).&lt;br&gt;
&lt;br&gt;
Written in c++ Visual Studio 2005, Win32, console application.&lt;br&gt;
&lt;br&gt;
It works based on the dot product of two vectos. There is info&lt;br&gt;
on the web about that as it applies to c++. Basically it states&lt;br&gt;
that the dot product of two unit vectors yields the cosine of the&lt;br&gt;
angle between them.&lt;br&gt;
&lt;br&gt;
///////////////////////////////////////////////////////////////////////&lt;br&gt;
&lt;br&gt;
// stdafx.h : include file for standard system include files,&lt;br&gt;
// or project specific include files that are used frequently, but&lt;br&gt;
// are changed infrequently&lt;br&gt;
//&lt;br&gt;
&lt;br&gt;
#pragma once&lt;br&gt;
&lt;br&gt;
#define WIN32_LEAN_AND_MEAN // Exclude rarely-used stuff from Windows&lt;br&gt;
headers&lt;br&gt;
#include &amp;lt;stdio.h&amp;gt;&lt;br&gt;
#include &amp;lt;tchar.h&amp;gt;&lt;br&gt;
///////////////////////////////////////////////////////////////////////&lt;br&gt;
// AngleBetweenTwoLines.cpp : Defines the entry point for the console&lt;br&gt;
application.&lt;br&gt;
//&lt;br&gt;
&lt;br&gt;
#include &quot;stdafx.h&quot;&lt;br&gt;
#include &amp;lt;math.h&amp;gt;&lt;br&gt;
&lt;br&gt;
//Radians to degrees.&lt;br&gt;
#define RTD 57.29577951 // 180/pi&lt;br&gt;
&lt;br&gt;
typedef struct fvector_s&lt;br&gt;
{float dx,dy,dz;&lt;br&gt;
}fvector_t;&lt;br&gt;
&lt;br&gt;
typedef struct fvertex_s&lt;br&gt;
{ float x,y,z;&lt;br&gt;
}fvertex_t;&lt;br&gt;
&lt;br&gt;
float fdot( fvector_t *v1, fvector_t *v2 );&lt;br&gt;
float fAngleDeg(fvector_t *v1, fvector_t *v2 );&lt;br&gt;
float fVectorLength(fvector_t *v);&lt;br&gt;
void fVectorNormalize(fvector_t *v);&lt;br&gt;
&lt;br&gt;
&lt;br&gt;
//--------------------------------------------------------------&lt;br&gt;
&lt;br&gt;
int _tmain(int argc, _TCHAR* argv[])&lt;br&gt;
{&lt;br&gt;
&lt;br&gt;
fvector_t v1,v2; //two vectors that represent our lines.&lt;br&gt;
fvertex_t p1,p2,p3,p4; // 4 vertices that represent our lines.&lt;br&gt;
float angle_between_lines;&lt;br&gt;
&lt;br&gt;
// Make 4 vertices.&lt;br&gt;
//For this example I will just hard code the values here.&lt;br&gt;
p1.x = 0; p1.y = 0; p1.z = 0;&lt;br&gt;
p2.x = 707; p2.y = 707; p2.z = 0;&lt;br&gt;
&lt;br&gt;
p3.x = 0; p3.y = 0; p3.z = 0;&lt;br&gt;
p4.x = 200; p4.y = 0; p4.z = 0;&lt;br&gt;
&lt;br&gt;
//make two lines (vectors) from these vertices&lt;br&gt;
v1.dx = p2.x - p1.x;&lt;br&gt;
v1.dy = p2.y - p1.y;&lt;br&gt;
v1.dz = p2.z - p1.z;&lt;br&gt;
&lt;br&gt;
v2.dx = p4.x - p3.x;&lt;br&gt;
v2.dy = p4.y - p3.y;&lt;br&gt;
v2.dz = p4.z - p3.z;&lt;br&gt;
&lt;br&gt;
//get the smallest angle between them.&lt;br&gt;
angle_between_lines = fAngleDeg(&amp;v1,&amp;v2);&lt;br&gt;
&lt;br&gt;
printf(&quot;The angle between these two lines is %f degrees.\r&lt;br&gt;
\n&quot;,angle_between_lines);&lt;br&gt;
&lt;br&gt;
return 0;&lt;br&gt;
}&lt;br&gt;
&lt;br&gt;
&lt;br&gt;
// returns the dot product of two vectors&lt;br&gt;
float fdot( fvector_t *v1, fvector_t *v2 )&lt;br&gt;
{return( (v1-&amp;gt;dx*v2-&amp;gt;dx) + (v1-&amp;gt;dy*v2-&amp;gt;dy) + (v1-&amp;gt;dz*v2-&amp;gt;dz) );}&lt;br&gt;
&lt;br&gt;
// returns the length of a vector&lt;br&gt;
float fVectorLength(fvector_t *v)&lt;br&gt;
{return (float)sqrt(fdot(v,v));}&lt;br&gt;
&lt;br&gt;
//return the angle in degrees between two lines&lt;br&gt;
float fAngleDeg(fvector_t *v1, fvector_t *v2 )&lt;br&gt;
{&lt;br&gt;
fVectorNormalize(v1);&lt;br&gt;
fVectorNormalize(v2);&lt;br&gt;
return (acos(fdot(v1,v2)) * RTD);&lt;br&gt;
}&lt;br&gt;
&lt;br&gt;
// Makes a unit vector, a vector whose length is 1.&lt;br&gt;
void fVectorNormalize(fvector_t *v)&lt;br&gt;
{&lt;br&gt;
float temp;&lt;br&gt;
&lt;br&gt;
temp = 1 / fVectorLength(v);&lt;br&gt;
&lt;br&gt;
v-&amp;gt;dx = v-&amp;gt;dx * temp;&lt;br&gt;
v-&amp;gt;dy = v-&amp;gt;dy * temp;&lt;br&gt;
v-&amp;gt;dz = v-&amp;gt;dz * temp;&lt;br&gt;
}&lt;br&gt;
///////////////////////////////////////////////////////////////////////</description>
    </item>
    <item>
      <pubDate>Wed, 05 Nov 2008 19:12:01 -0500</pubDate>
      <title>Re: How to create vectors from position data?</title>
      <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/238691#609245</link>
      <author>Roger Stafford</author>
      <description>&quot;Dai&quot; &amp;lt;relax2809@hotmail.com&amp;gt; wrote in message &amp;lt;gerkmn$sdr$1@fred.mathworks.com&amp;gt;...&lt;br&gt;
&amp;gt; Hi everyone&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; I have exported three dimensional coordinate data of markers placed along either side of a human spine into a text file. Each marker has three coordinates (x,y,z). I attempted to import the text file into MatLab to create vectors connecting each pair of markers and compute the angle of one vector relative to another but could not work out what functions to use. It would be greatly appreciated if anyone could advise me how to create vectors from coordinate data and compute angles thereafter. &lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; Thank you in advance&lt;br&gt;
&amp;gt; Dai&lt;br&gt;
&lt;br&gt;
&amp;nbsp;&amp;nbsp;Define position matrix P = [X,Y,Z] where X, Y, and Z are column arrays consisting of the three coordinates of successive data points.  Then do this:&lt;br&gt;
&lt;br&gt;
&amp;nbsp;V = diff(P); % Form 3D vectors between successive points&lt;br&gt;
&amp;nbsp;V1 = V(1:end-1,:);&lt;br&gt;
&amp;nbsp;V2 = V(2:end,:);&lt;br&gt;
&amp;nbsp;% Magnitudes of cross products:&lt;br&gt;
&amp;nbsp;cr = sqrt((V1(:,2).*V2(:,3)-V1(:,3).*V2(:,2)).^2+...&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;(V1(:,3).*V2(:,1)-V1(:,1).*V2(:,3)).^2+...&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;(V1(:,1).*V2(:,2)-V1(:,2).*V2(:,1)).^2);&lt;br&gt;
&amp;nbsp;% Dot products:&lt;br&gt;
&amp;nbsp;dt = V1(:,1).*V2(:,1)+V1(:,2).*V2(:,2)+V1(:,3).*V2(:,3);&lt;br&gt;
&amp;nbsp;% Angles between successive vectors:&lt;br&gt;
&amp;nbsp;A = atan2(cr,dt);&lt;br&gt;
&lt;br&gt;
&amp;nbsp;&amp;nbsp;If there are n points, P will have n rows of the three coordinates.  V will have n-1 rows of vectors between successive points of P.  A will be an array of n-2 angles between the successive vectors of V.  &lt;br&gt;
&lt;br&gt;
&amp;nbsp;&amp;nbsp;Note that cr is an array of the absolute values of the cross products of successive vectors in V, while dt is an array of their successive dot products.&lt;br&gt;
&lt;br&gt;
&amp;nbsp;&amp;nbsp;Note also that angles in A are the angles between successive vectors.  If you want the angles between successive line segments, just use -dt in the atan2 expression.  The one angle is the supplement of the other.&lt;br&gt;
&lt;br&gt;
&amp;nbsp;&amp;nbsp;Finally note that the i_th element of A will be the angle at the i+1_st vertex point of P.  There can be no angle defined at the first and last points of P.&lt;br&gt;
&lt;br&gt;
Roger Stafford</description>
    </item>
  </channel>
</rss>

