how one can write a nice vector parser, something that does pgfvecparseA=B-C; D=E x F;Translate in-line equations to TeX code (Any Package?)how to draw pitch, yaw and roll with 3d plotPass a 3d coordinate via pgfkeystkz-euclide, define points outside of tikzpictureHow to draw star in TikZ backgroundTikz: draw a vector pointing from one point to anotherHow to draw an elliptical arc in TikZ given only opposite extreme points (vertices) of the ellipse?How can one plot in 3D a matrix with LaTeX?Line up nested tikz enviroments or how to get rid of themHow to draw a square and its diagonals with arrows?beginfigure… endfigure is not working with tikz packagetikz pic: no pgfpointanchor possible inside the pic definitionHow to add a label to a vector and an angle?

What is a Samsaran Word™?

What does the same-ish mean?

Do Iron Man suits sport waste management systems?

Is there a hemisphere-neutral way of specifying a season?

How can a day be of 24 hours?

How to show a landlord what we have in savings?

What would the climate of a planetwide city be like?

Why were 5.25" floppy drives cheaper than 8"?

Is it a bad idea to plug the other end of ESD strap to wall ground?

Avoiding the "not like other girls" trope?

Why are UK visa biometrics appointments suspended at USCIS Application Support Centers?

How does a dynamic QR code work?

In the UK, is it possible to get a referendum by a court decision?

Unlock My Phone! February 2018

What exactly is ineptocracy?

Different meanings of こわい

Convert seconds to minutes

Am I breaking OOP practice with this architecture?

Placement of More Information/Help Icon button for Radio Buttons

In Bayesian inference, why are some terms dropped from the posterior predictive?

What Exploit Are These User Agents Trying to Use?

Is it possible to map the firing of neurons in the human brain so as to stimulate artificial memories in someone else?

files created then deleted at every second in tmp directory

Send out email when Apex Queueable fails and test it



how one can write a nice vector parser, something that does pgfvecparseA=B-C; D=E x F;


Translate in-line equations to TeX code (Any Package?)how to draw pitch, yaw and roll with 3d plotPass a 3d coordinate via pgfkeystkz-euclide, define points outside of tikzpictureHow to draw star in TikZ backgroundTikz: draw a vector pointing from one point to anotherHow to draw an elliptical arc in TikZ given only opposite extreme points (vertices) of the ellipse?How can one plot in 3D a matrix with LaTeX?Line up nested tikz enviroments or how to get rid of themHow to draw a square and its diagonals with arrows?beginfigure… endfigure is not working with tikz packagetikz pic: no pgfpointanchor possible inside the pic definitionHow to add a label to a vector and an angle?













4















I am often use coordinates of points to draw figure in geometry. I know that, we can add, minus coordinates of points, example



begintikzpicture
tkzDefPoints0/0/C',3/0/D',1/1/B'
coordinate (A') at ($(B')+(D')-(C')$);
endtikzpicture


If I have two points A(1,2,3) and B(4,5,6), how can I define vector AB as (B)-(A)?










share|improve this question
























  • Among the existing proposals, to my knowledge this one might be the most promising one. The open problem, though, is that the transformation is to "recorded". Some advanced transformation recording can be found here. But it seems that you are looking for something else.

    – marmot
    yesterday











  • Asymptote is a good choice

    – Black Mild
    yesterday











  • The bad news for you is that TikZ do not keep track of the 3d points. The code (1,2,3) is just fancy interface for a 2d point (that is a projection of this 3d point).

    – Kpym
    yesterday















4















I am often use coordinates of points to draw figure in geometry. I know that, we can add, minus coordinates of points, example



begintikzpicture
tkzDefPoints0/0/C',3/0/D',1/1/B'
coordinate (A') at ($(B')+(D')-(C')$);
endtikzpicture


If I have two points A(1,2,3) and B(4,5,6), how can I define vector AB as (B)-(A)?










share|improve this question
























  • Among the existing proposals, to my knowledge this one might be the most promising one. The open problem, though, is that the transformation is to "recorded". Some advanced transformation recording can be found here. But it seems that you are looking for something else.

    – marmot
    yesterday











  • Asymptote is a good choice

    – Black Mild
    yesterday











  • The bad news for you is that TikZ do not keep track of the 3d points. The code (1,2,3) is just fancy interface for a 2d point (that is a projection of this 3d point).

    – Kpym
    yesterday













4












4








4








I am often use coordinates of points to draw figure in geometry. I know that, we can add, minus coordinates of points, example



begintikzpicture
tkzDefPoints0/0/C',3/0/D',1/1/B'
coordinate (A') at ($(B')+(D')-(C')$);
endtikzpicture


If I have two points A(1,2,3) and B(4,5,6), how can I define vector AB as (B)-(A)?










share|improve this question
















I am often use coordinates of points to draw figure in geometry. I know that, we can add, minus coordinates of points, example



begintikzpicture
tkzDefPoints0/0/C',3/0/D',1/1/B'
coordinate (A') at ($(B')+(D')-(C')$);
endtikzpicture


If I have two points A(1,2,3) and B(4,5,6), how can I define vector AB as (B)-(A)?







tikz-pgf tikzmark






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited 2 days ago







minhthien_2016

















asked 2 days ago









minhthien_2016minhthien_2016

1,4221917




1,4221917












  • Among the existing proposals, to my knowledge this one might be the most promising one. The open problem, though, is that the transformation is to "recorded". Some advanced transformation recording can be found here. But it seems that you are looking for something else.

    – marmot
    yesterday











  • Asymptote is a good choice

    – Black Mild
    yesterday











  • The bad news for you is that TikZ do not keep track of the 3d points. The code (1,2,3) is just fancy interface for a 2d point (that is a projection of this 3d point).

    – Kpym
    yesterday

















  • Among the existing proposals, to my knowledge this one might be the most promising one. The open problem, though, is that the transformation is to "recorded". Some advanced transformation recording can be found here. But it seems that you are looking for something else.

    – marmot
    yesterday











  • Asymptote is a good choice

    – Black Mild
    yesterday











  • The bad news for you is that TikZ do not keep track of the 3d points. The code (1,2,3) is just fancy interface for a 2d point (that is a projection of this 3d point).

    – Kpym
    yesterday
















Among the existing proposals, to my knowledge this one might be the most promising one. The open problem, though, is that the transformation is to "recorded". Some advanced transformation recording can be found here. But it seems that you are looking for something else.

– marmot
yesterday





Among the existing proposals, to my knowledge this one might be the most promising one. The open problem, though, is that the transformation is to "recorded". Some advanced transformation recording can be found here. But it seems that you are looking for something else.

– marmot
yesterday













Asymptote is a good choice

– Black Mild
yesterday





Asymptote is a good choice

– Black Mild
yesterday













The bad news for you is that TikZ do not keep track of the 3d points. The code (1,2,3) is just fancy interface for a 2d point (that is a projection of this 3d point).

– Kpym
yesterday





The bad news for you is that TikZ do not keep track of the 3d points. The code (1,2,3) is just fancy interface for a 2d point (that is a projection of this 3d point).

– Kpym
yesterday










2 Answers
2






active

oldest

votes


















6














If you use the coordinates only for drawing, simply define each components of points as variable and then define coordinate points using them. For example:



documentclass[margin=3.14159mm]standalone
usepackagetikz,tikz-3dplot

begindocument
tdplotsetmaincoords60125
begintikzpicture
[scale=0.9,
tdplot_main_coords,
axis/.style=-latex,thick,
vector/.style=-stealth,red,very thick,
vector guide/.style=dashed,thick]

%standard tikz coordinate definition using x, y, z coords
% A(2,4,3), B(3,-1,4)
defAx2
defAy4
defAz3
defBx-1
defBy3
defBz4
coordinate (O) at (0,0,0);
coordinate (A) at (Ax,Ay,Az);
coordinate (B) at (Bx,By,Bz);
%draw axes
draw[axis] (0,0,0) -- (4,0,0) node[anchor=north east]$x$;
draw[axis] (0,0,0) -- (0,4,0) node[anchor=north west]$y$;
draw[axis] (0,0,0) -- (0,0,5) node[anchor=south]$z$;
%Dot at point
fill [blue] (A) circle (2pt);
fill [blue] (B) circle (2pt);
%draw a vector from O to A and O to B
draw[vector guide] (O)node[left=1mm] -- (A)node[above=-1mm,right]$P_1(Ax,Ay,Az)$;
draw[vector guide] (O) -- (B)node[above=-1mm,right]$P_2(Bx,By,Bz)$;

%draw vector D=AB
draw[vector] (A) -- (B)node[midway,above,sloped]$mathbfD$;
endtikzpicture
enddocument


enter image description here




SUPPLEMENT



With the permission of the answerer, I (Steven B Segletes) show here how the listofitems package can be used to streamline the syntax and maybe provide more readability. With it, I can create the arrays by reading a list, with the syntax readlistA2,4,3. Then, the expression A[] will spit back the array 2,4,3, which is sufficient for use in the present MWE. However, the individual components are also accessible as A[1], A[2], and A[3], which can be used for various calculations, as required.



documentclass[margin=3.14159mm]standalone
usepackagetikz,tikz-3dplot,listofitems

begindocument
tdplotsetmaincoords60125
begintikzpicture
[scale=0.9,
tdplot_main_coords,
axis/.style=-latex,thick,
vector/.style=-stealth,red,very thick,
vector guide/.style=dashed,thick]

%standard tikz coordinate definition using x, y, z coords
% A(2,4,3), B(3,-1,4)
readlistA2,4,3
readlistB-1,3,4
coordinate (O) at (0,0,0);
coordinate (A) at (A[]);
coordinate (B) at (B[]);
%draw axes
draw[axis] (0,0,0) -- (4,0,0) node[anchor=north east]$x$;
draw[axis] (0,0,0) -- (0,4,0) node[anchor=north west]$y$;
draw[axis] (0,0,0) -- (0,0,5) node[anchor=south]$z$;
%Dot at point
fill [blue] (A) circle (2pt);
fill [blue] (B) circle (2pt);
%draw a vector from O to A and O to B
draw[vector guide] (O)node[left=1mm] -- (A)node[above=-1mm,right]$P_1(A[])$;
draw[vector guide] (O) -- (B)node[above=-1mm,right]$P_2(B[])$;

%draw vector D=AB
draw[vector] (A) -- (B)node[midway,above,sloped]$mathbfD$;
endtikzpicture
enddocument





share|improve this answer

























  • Would you mind if I added a supplement to your answer?

    – Steven B. Segletes
    yesterday











  • @StevenB.Segletes, sure. I'd appreciate it.

    – ferahfeza
    yesterday







  • 1





    @ferahfeza margin = 3.14159mm wicked!

    – L. F.
    yesterday






  • 1





    Since language gap can easily occur on an international site as this, I would note for your benefit that "wicked" is a euphemism common to the Northeastern region of the United States, to mean "especially good." Thus, @L.F. was paying you a compliment, not the opposite.

    – Steven B. Segletes
    yesterday







  • 1





    Oh don't worry or fret. I recall being similarly confused the first time I visited Maine, U.S. ...and I live less than 500 miles away from there and speak nominally the same language..

    – Steven B. Segletes
    yesterday



















4














Just for fun, I wrote routines for 3D vector addition, subtraction, cross product and dot product (scalar treated as a 1D vector). I was trying to actually parse expressions of the form A+B but eventually gave up.



documentclassarticle
usepackagelistofitems
usepackagepgfmath
usepackageamsmath

makeatletter
newcommand@vecargs% reserve global names

newcommandvecadd
newcommandvecsub
newcommandvecdot
newcommandveccross
newcommandvecparse

defvecadd#1#2#3% #1 = #2 + #3
bgroup% local definitions
pgfmathsetmacro@x#2[1]+#3[1]%
pgfmathsetmacro@y#2[2]+#3[2]%
pgfmathsetmacro@z#2[3]+#3[3]%
xdef@vecargs@x,@y,@z%
egroup
readlist#1@vecargs

defvecsub#1#2#3% #1 = #2 - #3
bgroup% local definitions
pgfmathsetmacro@x#2[1]-#3[1]%
pgfmathsetmacro@y#2[2]-#3[2]%
pgfmathsetmacro@z#2[3]-#3[3]%
xdef@vecargs@x,@y,@z%
egroup
readlist#1@vecargs

defvecdot#1#2#3% #1 = #2 cdot #3
pgfmathsetmacro@vecargs#2[1]*#3[1] + #2[2]*#3[2] + #3[3]*#3[3]%
readlist#1@vecargs

defveccross#1#2#3% #1 = #2 times #3
bgroup% local definitions
pgfmathsetmacro@x#2[2]*#3[3] - #2[3]*#3[2]%
pgfmathsetmacro@y#2[3]*#3[1] - #2[1]*#3[3]%
pgfmathsetmacro@z#2[1]*#3[2] - #2[2]*#3[1]%
xdef@vecargs@x,@y,@z%
egroup
readlist#1@vecargs
makeatother

begindocument
readlistA1,2,3
readlistB4,5,6

vecaddCAB
C[]

vecsubCAB
C[]

vecdotCAB
C[]

veccrossCAB
C[]
enddocument



SUPPLEMENT



I hope John doesn't mind me (Steven B Segletes) adding his sought-after parser to the code. This allows input of the form vecparseCA+B, vecparseCA - B, vecparseCA .B, and vecparseCA xB (extra spaces of no consequence).



Support added not only for vecparseCA xB, but also vecparseCA x(3,5,6), vecparseC(3,5,6)xB and vecparseC(1,1,1)x(1,2,3).



documentclassarticle
usepackagelistofitems
usepackagepgfmath
usepackageamsmath

makeatletter
newcommand@vecargs% reserve global names

newcommandvecadd
newcommandvecsub
newcommandvecdot
newcommandveccross
newcommandvecparse

defvecadd#1#2#3% #1 = #2 + #3
bgroup% local definitions
pgfmathsetmacro@x#2[1]+#3[1]%
pgfmathsetmacro@y#2[2]+#3[2]%
pgfmathsetmacro@z#2[3]+#3[3]%
xdef@vecargs@x,@y,@z%
egroup
setsepchar,%
readlist#1@vecargs

defvecsub#1#2#3% #1 = #2 - #3
bgroup% local definitions
pgfmathsetmacro@x#2[1]-#3[1]%
pgfmathsetmacro@y#2[2]-#3[2]%
pgfmathsetmacro@z#2[3]-#3[3]%
xdef@vecargs@x,@y,@z%
egroup
setsepchar,%
readlist#1@vecargs

defvecdot#1#2#3% #1 = #2 cdot #3
pgfmathsetmacro@vecargs#2[1]*#3[1] + #2[2]*#3[2] + #3[3]*#3[3]%
setsepchar,%
readlist#1@vecargs

defveccross#1#2#3% #1 = #2 times #3
bgroup% local definitions
pgfmathsetmacro@x#2[2]*#3[3] - #2[3]*#3[2]%
pgfmathsetmacro@y#2[3]*#3[1] - #2[1]*#3[3]%
pgfmathsetmacro@z#2[1]*#3[2] - #2[2]*#3[1]%
xdef@vecargs@x,@y,@z%
egroup
setsepchar,%
readlist#1@vecargs

defvecparse#1#2%
setsepcharx%
readlist*@findop#2%
ifnumlistlen@findop[1]=1relax
itemtomacro@findop[1]tmpA
else
itemtomacro@findop[1,2]tmpF
setsepchar,%
readlisttmpEtmpF%
deftmpAtmpE%
fi
ifnumlistlen@findop[2]=1relax
itemtomacro@findop[2]tmpB
else
itemtomacro@findop[2,2]tmpD
setsepchar,%
readlisttmpCtmpD%
deftmpBtmpC%
fi
if+@findopsep[1]relax
deftmpvecadd#1%
elseif-@findopsep[1]relax
deftmpvecsub#1%
elseif.@findopsep[1]relax
deftmpvecdot#1%
elseif x@findopsep[1]relax
deftmpveccross#1%
fifififi
expandafterexpandafterexpandaftertmpexpandaftertmpAtmpB

makeatother

begindocument
readlistA1,2,3
readlistB4,5,6

vecaddCAB
C[]

VP:vecparseCA+B
C[]

vecsubCAB
C[]

VP:vecparseCA - B
C[]

vecdotCAB
C[]

VP:vecparseCA .B
C[]

veccrossCAB
C[]

VP:vecparseCA xB
C[]

VP:vecparseCA x(3,5,6)
C[]

VP:vecparseC(3,5,6)xB
C[]

VP:vecparseC(1,1,1)x(1,2,3)
C[]

enddocument


enter image description here






share|improve this answer

























  • That is really nice.

    – Steven B. Segletes
    yesterday











  • I hope you don't mind my edit.

    – Steven B. Segletes
    yesterday






  • 1





    I was thinking more of expressions like A+(4,5,6) which are a lot easier when A expands to 1,2,3 directly.

    – John Kormylo
    11 hours ago






  • 1





    @marmot I think it would be possible, but would require quite a bit more effort. Any time the input is allowed to be in a free format, requiring sub-evaluations of the components that can than comprise larger components...well a more careful approach is required.

    – Steven B. Segletes
    9 hours ago






  • 1





    @marmot It would likely require an approach like tex.stackexchange.com/questions/332012/…, where an order of operations hierarchy is established, and the input parsed along those lines. But rather than just typesetting the result, vector mechanics needs to be performed.

    – Steven B. Segletes
    8 hours ago











Your Answer








StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "85"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);

else
createEditor();

);

function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: false,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);



);













draft saved

draft discarded


















StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2ftex.stackexchange.com%2fquestions%2f482518%2fhow-one-can-write-a-nice-vector-parser-something-that-does-pgfvecparse-a-b%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown

























2 Answers
2






active

oldest

votes








2 Answers
2






active

oldest

votes









active

oldest

votes






active

oldest

votes









6














If you use the coordinates only for drawing, simply define each components of points as variable and then define coordinate points using them. For example:



documentclass[margin=3.14159mm]standalone
usepackagetikz,tikz-3dplot

begindocument
tdplotsetmaincoords60125
begintikzpicture
[scale=0.9,
tdplot_main_coords,
axis/.style=-latex,thick,
vector/.style=-stealth,red,very thick,
vector guide/.style=dashed,thick]

%standard tikz coordinate definition using x, y, z coords
% A(2,4,3), B(3,-1,4)
defAx2
defAy4
defAz3
defBx-1
defBy3
defBz4
coordinate (O) at (0,0,0);
coordinate (A) at (Ax,Ay,Az);
coordinate (B) at (Bx,By,Bz);
%draw axes
draw[axis] (0,0,0) -- (4,0,0) node[anchor=north east]$x$;
draw[axis] (0,0,0) -- (0,4,0) node[anchor=north west]$y$;
draw[axis] (0,0,0) -- (0,0,5) node[anchor=south]$z$;
%Dot at point
fill [blue] (A) circle (2pt);
fill [blue] (B) circle (2pt);
%draw a vector from O to A and O to B
draw[vector guide] (O)node[left=1mm] -- (A)node[above=-1mm,right]$P_1(Ax,Ay,Az)$;
draw[vector guide] (O) -- (B)node[above=-1mm,right]$P_2(Bx,By,Bz)$;

%draw vector D=AB
draw[vector] (A) -- (B)node[midway,above,sloped]$mathbfD$;
endtikzpicture
enddocument


enter image description here




SUPPLEMENT



With the permission of the answerer, I (Steven B Segletes) show here how the listofitems package can be used to streamline the syntax and maybe provide more readability. With it, I can create the arrays by reading a list, with the syntax readlistA2,4,3. Then, the expression A[] will spit back the array 2,4,3, which is sufficient for use in the present MWE. However, the individual components are also accessible as A[1], A[2], and A[3], which can be used for various calculations, as required.



documentclass[margin=3.14159mm]standalone
usepackagetikz,tikz-3dplot,listofitems

begindocument
tdplotsetmaincoords60125
begintikzpicture
[scale=0.9,
tdplot_main_coords,
axis/.style=-latex,thick,
vector/.style=-stealth,red,very thick,
vector guide/.style=dashed,thick]

%standard tikz coordinate definition using x, y, z coords
% A(2,4,3), B(3,-1,4)
readlistA2,4,3
readlistB-1,3,4
coordinate (O) at (0,0,0);
coordinate (A) at (A[]);
coordinate (B) at (B[]);
%draw axes
draw[axis] (0,0,0) -- (4,0,0) node[anchor=north east]$x$;
draw[axis] (0,0,0) -- (0,4,0) node[anchor=north west]$y$;
draw[axis] (0,0,0) -- (0,0,5) node[anchor=south]$z$;
%Dot at point
fill [blue] (A) circle (2pt);
fill [blue] (B) circle (2pt);
%draw a vector from O to A and O to B
draw[vector guide] (O)node[left=1mm] -- (A)node[above=-1mm,right]$P_1(A[])$;
draw[vector guide] (O) -- (B)node[above=-1mm,right]$P_2(B[])$;

%draw vector D=AB
draw[vector] (A) -- (B)node[midway,above,sloped]$mathbfD$;
endtikzpicture
enddocument





share|improve this answer

























  • Would you mind if I added a supplement to your answer?

    – Steven B. Segletes
    yesterday











  • @StevenB.Segletes, sure. I'd appreciate it.

    – ferahfeza
    yesterday







  • 1





    @ferahfeza margin = 3.14159mm wicked!

    – L. F.
    yesterday






  • 1





    Since language gap can easily occur on an international site as this, I would note for your benefit that "wicked" is a euphemism common to the Northeastern region of the United States, to mean "especially good." Thus, @L.F. was paying you a compliment, not the opposite.

    – Steven B. Segletes
    yesterday







  • 1





    Oh don't worry or fret. I recall being similarly confused the first time I visited Maine, U.S. ...and I live less than 500 miles away from there and speak nominally the same language..

    – Steven B. Segletes
    yesterday
















6














If you use the coordinates only for drawing, simply define each components of points as variable and then define coordinate points using them. For example:



documentclass[margin=3.14159mm]standalone
usepackagetikz,tikz-3dplot

begindocument
tdplotsetmaincoords60125
begintikzpicture
[scale=0.9,
tdplot_main_coords,
axis/.style=-latex,thick,
vector/.style=-stealth,red,very thick,
vector guide/.style=dashed,thick]

%standard tikz coordinate definition using x, y, z coords
% A(2,4,3), B(3,-1,4)
defAx2
defAy4
defAz3
defBx-1
defBy3
defBz4
coordinate (O) at (0,0,0);
coordinate (A) at (Ax,Ay,Az);
coordinate (B) at (Bx,By,Bz);
%draw axes
draw[axis] (0,0,0) -- (4,0,0) node[anchor=north east]$x$;
draw[axis] (0,0,0) -- (0,4,0) node[anchor=north west]$y$;
draw[axis] (0,0,0) -- (0,0,5) node[anchor=south]$z$;
%Dot at point
fill [blue] (A) circle (2pt);
fill [blue] (B) circle (2pt);
%draw a vector from O to A and O to B
draw[vector guide] (O)node[left=1mm] -- (A)node[above=-1mm,right]$P_1(Ax,Ay,Az)$;
draw[vector guide] (O) -- (B)node[above=-1mm,right]$P_2(Bx,By,Bz)$;

%draw vector D=AB
draw[vector] (A) -- (B)node[midway,above,sloped]$mathbfD$;
endtikzpicture
enddocument


enter image description here




SUPPLEMENT



With the permission of the answerer, I (Steven B Segletes) show here how the listofitems package can be used to streamline the syntax and maybe provide more readability. With it, I can create the arrays by reading a list, with the syntax readlistA2,4,3. Then, the expression A[] will spit back the array 2,4,3, which is sufficient for use in the present MWE. However, the individual components are also accessible as A[1], A[2], and A[3], which can be used for various calculations, as required.



documentclass[margin=3.14159mm]standalone
usepackagetikz,tikz-3dplot,listofitems

begindocument
tdplotsetmaincoords60125
begintikzpicture
[scale=0.9,
tdplot_main_coords,
axis/.style=-latex,thick,
vector/.style=-stealth,red,very thick,
vector guide/.style=dashed,thick]

%standard tikz coordinate definition using x, y, z coords
% A(2,4,3), B(3,-1,4)
readlistA2,4,3
readlistB-1,3,4
coordinate (O) at (0,0,0);
coordinate (A) at (A[]);
coordinate (B) at (B[]);
%draw axes
draw[axis] (0,0,0) -- (4,0,0) node[anchor=north east]$x$;
draw[axis] (0,0,0) -- (0,4,0) node[anchor=north west]$y$;
draw[axis] (0,0,0) -- (0,0,5) node[anchor=south]$z$;
%Dot at point
fill [blue] (A) circle (2pt);
fill [blue] (B) circle (2pt);
%draw a vector from O to A and O to B
draw[vector guide] (O)node[left=1mm] -- (A)node[above=-1mm,right]$P_1(A[])$;
draw[vector guide] (O) -- (B)node[above=-1mm,right]$P_2(B[])$;

%draw vector D=AB
draw[vector] (A) -- (B)node[midway,above,sloped]$mathbfD$;
endtikzpicture
enddocument





share|improve this answer

























  • Would you mind if I added a supplement to your answer?

    – Steven B. Segletes
    yesterday











  • @StevenB.Segletes, sure. I'd appreciate it.

    – ferahfeza
    yesterday







  • 1





    @ferahfeza margin = 3.14159mm wicked!

    – L. F.
    yesterday






  • 1





    Since language gap can easily occur on an international site as this, I would note for your benefit that "wicked" is a euphemism common to the Northeastern region of the United States, to mean "especially good." Thus, @L.F. was paying you a compliment, not the opposite.

    – Steven B. Segletes
    yesterday







  • 1





    Oh don't worry or fret. I recall being similarly confused the first time I visited Maine, U.S. ...and I live less than 500 miles away from there and speak nominally the same language..

    – Steven B. Segletes
    yesterday














6












6








6







If you use the coordinates only for drawing, simply define each components of points as variable and then define coordinate points using them. For example:



documentclass[margin=3.14159mm]standalone
usepackagetikz,tikz-3dplot

begindocument
tdplotsetmaincoords60125
begintikzpicture
[scale=0.9,
tdplot_main_coords,
axis/.style=-latex,thick,
vector/.style=-stealth,red,very thick,
vector guide/.style=dashed,thick]

%standard tikz coordinate definition using x, y, z coords
% A(2,4,3), B(3,-1,4)
defAx2
defAy4
defAz3
defBx-1
defBy3
defBz4
coordinate (O) at (0,0,0);
coordinate (A) at (Ax,Ay,Az);
coordinate (B) at (Bx,By,Bz);
%draw axes
draw[axis] (0,0,0) -- (4,0,0) node[anchor=north east]$x$;
draw[axis] (0,0,0) -- (0,4,0) node[anchor=north west]$y$;
draw[axis] (0,0,0) -- (0,0,5) node[anchor=south]$z$;
%Dot at point
fill [blue] (A) circle (2pt);
fill [blue] (B) circle (2pt);
%draw a vector from O to A and O to B
draw[vector guide] (O)node[left=1mm] -- (A)node[above=-1mm,right]$P_1(Ax,Ay,Az)$;
draw[vector guide] (O) -- (B)node[above=-1mm,right]$P_2(Bx,By,Bz)$;

%draw vector D=AB
draw[vector] (A) -- (B)node[midway,above,sloped]$mathbfD$;
endtikzpicture
enddocument


enter image description here




SUPPLEMENT



With the permission of the answerer, I (Steven B Segletes) show here how the listofitems package can be used to streamline the syntax and maybe provide more readability. With it, I can create the arrays by reading a list, with the syntax readlistA2,4,3. Then, the expression A[] will spit back the array 2,4,3, which is sufficient for use in the present MWE. However, the individual components are also accessible as A[1], A[2], and A[3], which can be used for various calculations, as required.



documentclass[margin=3.14159mm]standalone
usepackagetikz,tikz-3dplot,listofitems

begindocument
tdplotsetmaincoords60125
begintikzpicture
[scale=0.9,
tdplot_main_coords,
axis/.style=-latex,thick,
vector/.style=-stealth,red,very thick,
vector guide/.style=dashed,thick]

%standard tikz coordinate definition using x, y, z coords
% A(2,4,3), B(3,-1,4)
readlistA2,4,3
readlistB-1,3,4
coordinate (O) at (0,0,0);
coordinate (A) at (A[]);
coordinate (B) at (B[]);
%draw axes
draw[axis] (0,0,0) -- (4,0,0) node[anchor=north east]$x$;
draw[axis] (0,0,0) -- (0,4,0) node[anchor=north west]$y$;
draw[axis] (0,0,0) -- (0,0,5) node[anchor=south]$z$;
%Dot at point
fill [blue] (A) circle (2pt);
fill [blue] (B) circle (2pt);
%draw a vector from O to A and O to B
draw[vector guide] (O)node[left=1mm] -- (A)node[above=-1mm,right]$P_1(A[])$;
draw[vector guide] (O) -- (B)node[above=-1mm,right]$P_2(B[])$;

%draw vector D=AB
draw[vector] (A) -- (B)node[midway,above,sloped]$mathbfD$;
endtikzpicture
enddocument





share|improve this answer















If you use the coordinates only for drawing, simply define each components of points as variable and then define coordinate points using them. For example:



documentclass[margin=3.14159mm]standalone
usepackagetikz,tikz-3dplot

begindocument
tdplotsetmaincoords60125
begintikzpicture
[scale=0.9,
tdplot_main_coords,
axis/.style=-latex,thick,
vector/.style=-stealth,red,very thick,
vector guide/.style=dashed,thick]

%standard tikz coordinate definition using x, y, z coords
% A(2,4,3), B(3,-1,4)
defAx2
defAy4
defAz3
defBx-1
defBy3
defBz4
coordinate (O) at (0,0,0);
coordinate (A) at (Ax,Ay,Az);
coordinate (B) at (Bx,By,Bz);
%draw axes
draw[axis] (0,0,0) -- (4,0,0) node[anchor=north east]$x$;
draw[axis] (0,0,0) -- (0,4,0) node[anchor=north west]$y$;
draw[axis] (0,0,0) -- (0,0,5) node[anchor=south]$z$;
%Dot at point
fill [blue] (A) circle (2pt);
fill [blue] (B) circle (2pt);
%draw a vector from O to A and O to B
draw[vector guide] (O)node[left=1mm] -- (A)node[above=-1mm,right]$P_1(Ax,Ay,Az)$;
draw[vector guide] (O) -- (B)node[above=-1mm,right]$P_2(Bx,By,Bz)$;

%draw vector D=AB
draw[vector] (A) -- (B)node[midway,above,sloped]$mathbfD$;
endtikzpicture
enddocument


enter image description here




SUPPLEMENT



With the permission of the answerer, I (Steven B Segletes) show here how the listofitems package can be used to streamline the syntax and maybe provide more readability. With it, I can create the arrays by reading a list, with the syntax readlistA2,4,3. Then, the expression A[] will spit back the array 2,4,3, which is sufficient for use in the present MWE. However, the individual components are also accessible as A[1], A[2], and A[3], which can be used for various calculations, as required.



documentclass[margin=3.14159mm]standalone
usepackagetikz,tikz-3dplot,listofitems

begindocument
tdplotsetmaincoords60125
begintikzpicture
[scale=0.9,
tdplot_main_coords,
axis/.style=-latex,thick,
vector/.style=-stealth,red,very thick,
vector guide/.style=dashed,thick]

%standard tikz coordinate definition using x, y, z coords
% A(2,4,3), B(3,-1,4)
readlistA2,4,3
readlistB-1,3,4
coordinate (O) at (0,0,0);
coordinate (A) at (A[]);
coordinate (B) at (B[]);
%draw axes
draw[axis] (0,0,0) -- (4,0,0) node[anchor=north east]$x$;
draw[axis] (0,0,0) -- (0,4,0) node[anchor=north west]$y$;
draw[axis] (0,0,0) -- (0,0,5) node[anchor=south]$z$;
%Dot at point
fill [blue] (A) circle (2pt);
fill [blue] (B) circle (2pt);
%draw a vector from O to A and O to B
draw[vector guide] (O)node[left=1mm] -- (A)node[above=-1mm,right]$P_1(A[])$;
draw[vector guide] (O) -- (B)node[above=-1mm,right]$P_2(B[])$;

%draw vector D=AB
draw[vector] (A) -- (B)node[midway,above,sloped]$mathbfD$;
endtikzpicture
enddocument






share|improve this answer














share|improve this answer



share|improve this answer








edited yesterday









Steven B. Segletes

160k9205413




160k9205413










answered yesterday









ferahfezaferahfeza

7,33411933




7,33411933












  • Would you mind if I added a supplement to your answer?

    – Steven B. Segletes
    yesterday











  • @StevenB.Segletes, sure. I'd appreciate it.

    – ferahfeza
    yesterday







  • 1





    @ferahfeza margin = 3.14159mm wicked!

    – L. F.
    yesterday






  • 1





    Since language gap can easily occur on an international site as this, I would note for your benefit that "wicked" is a euphemism common to the Northeastern region of the United States, to mean "especially good." Thus, @L.F. was paying you a compliment, not the opposite.

    – Steven B. Segletes
    yesterday







  • 1





    Oh don't worry or fret. I recall being similarly confused the first time I visited Maine, U.S. ...and I live less than 500 miles away from there and speak nominally the same language..

    – Steven B. Segletes
    yesterday


















  • Would you mind if I added a supplement to your answer?

    – Steven B. Segletes
    yesterday











  • @StevenB.Segletes, sure. I'd appreciate it.

    – ferahfeza
    yesterday







  • 1





    @ferahfeza margin = 3.14159mm wicked!

    – L. F.
    yesterday






  • 1





    Since language gap can easily occur on an international site as this, I would note for your benefit that "wicked" is a euphemism common to the Northeastern region of the United States, to mean "especially good." Thus, @L.F. was paying you a compliment, not the opposite.

    – Steven B. Segletes
    yesterday







  • 1





    Oh don't worry or fret. I recall being similarly confused the first time I visited Maine, U.S. ...and I live less than 500 miles away from there and speak nominally the same language..

    – Steven B. Segletes
    yesterday

















Would you mind if I added a supplement to your answer?

– Steven B. Segletes
yesterday





Would you mind if I added a supplement to your answer?

– Steven B. Segletes
yesterday













@StevenB.Segletes, sure. I'd appreciate it.

– ferahfeza
yesterday






@StevenB.Segletes, sure. I'd appreciate it.

– ferahfeza
yesterday





1




1





@ferahfeza margin = 3.14159mm wicked!

– L. F.
yesterday





@ferahfeza margin = 3.14159mm wicked!

– L. F.
yesterday




1




1





Since language gap can easily occur on an international site as this, I would note for your benefit that "wicked" is a euphemism common to the Northeastern region of the United States, to mean "especially good." Thus, @L.F. was paying you a compliment, not the opposite.

– Steven B. Segletes
yesterday






Since language gap can easily occur on an international site as this, I would note for your benefit that "wicked" is a euphemism common to the Northeastern region of the United States, to mean "especially good." Thus, @L.F. was paying you a compliment, not the opposite.

– Steven B. Segletes
yesterday





1




1





Oh don't worry or fret. I recall being similarly confused the first time I visited Maine, U.S. ...and I live less than 500 miles away from there and speak nominally the same language..

– Steven B. Segletes
yesterday






Oh don't worry or fret. I recall being similarly confused the first time I visited Maine, U.S. ...and I live less than 500 miles away from there and speak nominally the same language..

– Steven B. Segletes
yesterday












4














Just for fun, I wrote routines for 3D vector addition, subtraction, cross product and dot product (scalar treated as a 1D vector). I was trying to actually parse expressions of the form A+B but eventually gave up.



documentclassarticle
usepackagelistofitems
usepackagepgfmath
usepackageamsmath

makeatletter
newcommand@vecargs% reserve global names

newcommandvecadd
newcommandvecsub
newcommandvecdot
newcommandveccross
newcommandvecparse

defvecadd#1#2#3% #1 = #2 + #3
bgroup% local definitions
pgfmathsetmacro@x#2[1]+#3[1]%
pgfmathsetmacro@y#2[2]+#3[2]%
pgfmathsetmacro@z#2[3]+#3[3]%
xdef@vecargs@x,@y,@z%
egroup
readlist#1@vecargs

defvecsub#1#2#3% #1 = #2 - #3
bgroup% local definitions
pgfmathsetmacro@x#2[1]-#3[1]%
pgfmathsetmacro@y#2[2]-#3[2]%
pgfmathsetmacro@z#2[3]-#3[3]%
xdef@vecargs@x,@y,@z%
egroup
readlist#1@vecargs

defvecdot#1#2#3% #1 = #2 cdot #3
pgfmathsetmacro@vecargs#2[1]*#3[1] + #2[2]*#3[2] + #3[3]*#3[3]%
readlist#1@vecargs

defveccross#1#2#3% #1 = #2 times #3
bgroup% local definitions
pgfmathsetmacro@x#2[2]*#3[3] - #2[3]*#3[2]%
pgfmathsetmacro@y#2[3]*#3[1] - #2[1]*#3[3]%
pgfmathsetmacro@z#2[1]*#3[2] - #2[2]*#3[1]%
xdef@vecargs@x,@y,@z%
egroup
readlist#1@vecargs
makeatother

begindocument
readlistA1,2,3
readlistB4,5,6

vecaddCAB
C[]

vecsubCAB
C[]

vecdotCAB
C[]

veccrossCAB
C[]
enddocument



SUPPLEMENT



I hope John doesn't mind me (Steven B Segletes) adding his sought-after parser to the code. This allows input of the form vecparseCA+B, vecparseCA - B, vecparseCA .B, and vecparseCA xB (extra spaces of no consequence).



Support added not only for vecparseCA xB, but also vecparseCA x(3,5,6), vecparseC(3,5,6)xB and vecparseC(1,1,1)x(1,2,3).



documentclassarticle
usepackagelistofitems
usepackagepgfmath
usepackageamsmath

makeatletter
newcommand@vecargs% reserve global names

newcommandvecadd
newcommandvecsub
newcommandvecdot
newcommandveccross
newcommandvecparse

defvecadd#1#2#3% #1 = #2 + #3
bgroup% local definitions
pgfmathsetmacro@x#2[1]+#3[1]%
pgfmathsetmacro@y#2[2]+#3[2]%
pgfmathsetmacro@z#2[3]+#3[3]%
xdef@vecargs@x,@y,@z%
egroup
setsepchar,%
readlist#1@vecargs

defvecsub#1#2#3% #1 = #2 - #3
bgroup% local definitions
pgfmathsetmacro@x#2[1]-#3[1]%
pgfmathsetmacro@y#2[2]-#3[2]%
pgfmathsetmacro@z#2[3]-#3[3]%
xdef@vecargs@x,@y,@z%
egroup
setsepchar,%
readlist#1@vecargs

defvecdot#1#2#3% #1 = #2 cdot #3
pgfmathsetmacro@vecargs#2[1]*#3[1] + #2[2]*#3[2] + #3[3]*#3[3]%
setsepchar,%
readlist#1@vecargs

defveccross#1#2#3% #1 = #2 times #3
bgroup% local definitions
pgfmathsetmacro@x#2[2]*#3[3] - #2[3]*#3[2]%
pgfmathsetmacro@y#2[3]*#3[1] - #2[1]*#3[3]%
pgfmathsetmacro@z#2[1]*#3[2] - #2[2]*#3[1]%
xdef@vecargs@x,@y,@z%
egroup
setsepchar,%
readlist#1@vecargs

defvecparse#1#2%
setsepcharx%
readlist*@findop#2%
ifnumlistlen@findop[1]=1relax
itemtomacro@findop[1]tmpA
else
itemtomacro@findop[1,2]tmpF
setsepchar,%
readlisttmpEtmpF%
deftmpAtmpE%
fi
ifnumlistlen@findop[2]=1relax
itemtomacro@findop[2]tmpB
else
itemtomacro@findop[2,2]tmpD
setsepchar,%
readlisttmpCtmpD%
deftmpBtmpC%
fi
if+@findopsep[1]relax
deftmpvecadd#1%
elseif-@findopsep[1]relax
deftmpvecsub#1%
elseif.@findopsep[1]relax
deftmpvecdot#1%
elseif x@findopsep[1]relax
deftmpveccross#1%
fifififi
expandafterexpandafterexpandaftertmpexpandaftertmpAtmpB

makeatother

begindocument
readlistA1,2,3
readlistB4,5,6

vecaddCAB
C[]

VP:vecparseCA+B
C[]

vecsubCAB
C[]

VP:vecparseCA - B
C[]

vecdotCAB
C[]

VP:vecparseCA .B
C[]

veccrossCAB
C[]

VP:vecparseCA xB
C[]

VP:vecparseCA x(3,5,6)
C[]

VP:vecparseC(3,5,6)xB
C[]

VP:vecparseC(1,1,1)x(1,2,3)
C[]

enddocument


enter image description here






share|improve this answer

























  • That is really nice.

    – Steven B. Segletes
    yesterday











  • I hope you don't mind my edit.

    – Steven B. Segletes
    yesterday






  • 1





    I was thinking more of expressions like A+(4,5,6) which are a lot easier when A expands to 1,2,3 directly.

    – John Kormylo
    11 hours ago






  • 1





    @marmot I think it would be possible, but would require quite a bit more effort. Any time the input is allowed to be in a free format, requiring sub-evaluations of the components that can than comprise larger components...well a more careful approach is required.

    – Steven B. Segletes
    9 hours ago






  • 1





    @marmot It would likely require an approach like tex.stackexchange.com/questions/332012/…, where an order of operations hierarchy is established, and the input parsed along those lines. But rather than just typesetting the result, vector mechanics needs to be performed.

    – Steven B. Segletes
    8 hours ago















4














Just for fun, I wrote routines for 3D vector addition, subtraction, cross product and dot product (scalar treated as a 1D vector). I was trying to actually parse expressions of the form A+B but eventually gave up.



documentclassarticle
usepackagelistofitems
usepackagepgfmath
usepackageamsmath

makeatletter
newcommand@vecargs% reserve global names

newcommandvecadd
newcommandvecsub
newcommandvecdot
newcommandveccross
newcommandvecparse

defvecadd#1#2#3% #1 = #2 + #3
bgroup% local definitions
pgfmathsetmacro@x#2[1]+#3[1]%
pgfmathsetmacro@y#2[2]+#3[2]%
pgfmathsetmacro@z#2[3]+#3[3]%
xdef@vecargs@x,@y,@z%
egroup
readlist#1@vecargs

defvecsub#1#2#3% #1 = #2 - #3
bgroup% local definitions
pgfmathsetmacro@x#2[1]-#3[1]%
pgfmathsetmacro@y#2[2]-#3[2]%
pgfmathsetmacro@z#2[3]-#3[3]%
xdef@vecargs@x,@y,@z%
egroup
readlist#1@vecargs

defvecdot#1#2#3% #1 = #2 cdot #3
pgfmathsetmacro@vecargs#2[1]*#3[1] + #2[2]*#3[2] + #3[3]*#3[3]%
readlist#1@vecargs

defveccross#1#2#3% #1 = #2 times #3
bgroup% local definitions
pgfmathsetmacro@x#2[2]*#3[3] - #2[3]*#3[2]%
pgfmathsetmacro@y#2[3]*#3[1] - #2[1]*#3[3]%
pgfmathsetmacro@z#2[1]*#3[2] - #2[2]*#3[1]%
xdef@vecargs@x,@y,@z%
egroup
readlist#1@vecargs
makeatother

begindocument
readlistA1,2,3
readlistB4,5,6

vecaddCAB
C[]

vecsubCAB
C[]

vecdotCAB
C[]

veccrossCAB
C[]
enddocument



SUPPLEMENT



I hope John doesn't mind me (Steven B Segletes) adding his sought-after parser to the code. This allows input of the form vecparseCA+B, vecparseCA - B, vecparseCA .B, and vecparseCA xB (extra spaces of no consequence).



Support added not only for vecparseCA xB, but also vecparseCA x(3,5,6), vecparseC(3,5,6)xB and vecparseC(1,1,1)x(1,2,3).



documentclassarticle
usepackagelistofitems
usepackagepgfmath
usepackageamsmath

makeatletter
newcommand@vecargs% reserve global names

newcommandvecadd
newcommandvecsub
newcommandvecdot
newcommandveccross
newcommandvecparse

defvecadd#1#2#3% #1 = #2 + #3
bgroup% local definitions
pgfmathsetmacro@x#2[1]+#3[1]%
pgfmathsetmacro@y#2[2]+#3[2]%
pgfmathsetmacro@z#2[3]+#3[3]%
xdef@vecargs@x,@y,@z%
egroup
setsepchar,%
readlist#1@vecargs

defvecsub#1#2#3% #1 = #2 - #3
bgroup% local definitions
pgfmathsetmacro@x#2[1]-#3[1]%
pgfmathsetmacro@y#2[2]-#3[2]%
pgfmathsetmacro@z#2[3]-#3[3]%
xdef@vecargs@x,@y,@z%
egroup
setsepchar,%
readlist#1@vecargs

defvecdot#1#2#3% #1 = #2 cdot #3
pgfmathsetmacro@vecargs#2[1]*#3[1] + #2[2]*#3[2] + #3[3]*#3[3]%
setsepchar,%
readlist#1@vecargs

defveccross#1#2#3% #1 = #2 times #3
bgroup% local definitions
pgfmathsetmacro@x#2[2]*#3[3] - #2[3]*#3[2]%
pgfmathsetmacro@y#2[3]*#3[1] - #2[1]*#3[3]%
pgfmathsetmacro@z#2[1]*#3[2] - #2[2]*#3[1]%
xdef@vecargs@x,@y,@z%
egroup
setsepchar,%
readlist#1@vecargs

defvecparse#1#2%
setsepcharx%
readlist*@findop#2%
ifnumlistlen@findop[1]=1relax
itemtomacro@findop[1]tmpA
else
itemtomacro@findop[1,2]tmpF
setsepchar,%
readlisttmpEtmpF%
deftmpAtmpE%
fi
ifnumlistlen@findop[2]=1relax
itemtomacro@findop[2]tmpB
else
itemtomacro@findop[2,2]tmpD
setsepchar,%
readlisttmpCtmpD%
deftmpBtmpC%
fi
if+@findopsep[1]relax
deftmpvecadd#1%
elseif-@findopsep[1]relax
deftmpvecsub#1%
elseif.@findopsep[1]relax
deftmpvecdot#1%
elseif x@findopsep[1]relax
deftmpveccross#1%
fifififi
expandafterexpandafterexpandaftertmpexpandaftertmpAtmpB

makeatother

begindocument
readlistA1,2,3
readlistB4,5,6

vecaddCAB
C[]

VP:vecparseCA+B
C[]

vecsubCAB
C[]

VP:vecparseCA - B
C[]

vecdotCAB
C[]

VP:vecparseCA .B
C[]

veccrossCAB
C[]

VP:vecparseCA xB
C[]

VP:vecparseCA x(3,5,6)
C[]

VP:vecparseC(3,5,6)xB
C[]

VP:vecparseC(1,1,1)x(1,2,3)
C[]

enddocument


enter image description here






share|improve this answer

























  • That is really nice.

    – Steven B. Segletes
    yesterday











  • I hope you don't mind my edit.

    – Steven B. Segletes
    yesterday






  • 1





    I was thinking more of expressions like A+(4,5,6) which are a lot easier when A expands to 1,2,3 directly.

    – John Kormylo
    11 hours ago






  • 1





    @marmot I think it would be possible, but would require quite a bit more effort. Any time the input is allowed to be in a free format, requiring sub-evaluations of the components that can than comprise larger components...well a more careful approach is required.

    – Steven B. Segletes
    9 hours ago






  • 1





    @marmot It would likely require an approach like tex.stackexchange.com/questions/332012/…, where an order of operations hierarchy is established, and the input parsed along those lines. But rather than just typesetting the result, vector mechanics needs to be performed.

    – Steven B. Segletes
    8 hours ago













4












4








4







Just for fun, I wrote routines for 3D vector addition, subtraction, cross product and dot product (scalar treated as a 1D vector). I was trying to actually parse expressions of the form A+B but eventually gave up.



documentclassarticle
usepackagelistofitems
usepackagepgfmath
usepackageamsmath

makeatletter
newcommand@vecargs% reserve global names

newcommandvecadd
newcommandvecsub
newcommandvecdot
newcommandveccross
newcommandvecparse

defvecadd#1#2#3% #1 = #2 + #3
bgroup% local definitions
pgfmathsetmacro@x#2[1]+#3[1]%
pgfmathsetmacro@y#2[2]+#3[2]%
pgfmathsetmacro@z#2[3]+#3[3]%
xdef@vecargs@x,@y,@z%
egroup
readlist#1@vecargs

defvecsub#1#2#3% #1 = #2 - #3
bgroup% local definitions
pgfmathsetmacro@x#2[1]-#3[1]%
pgfmathsetmacro@y#2[2]-#3[2]%
pgfmathsetmacro@z#2[3]-#3[3]%
xdef@vecargs@x,@y,@z%
egroup
readlist#1@vecargs

defvecdot#1#2#3% #1 = #2 cdot #3
pgfmathsetmacro@vecargs#2[1]*#3[1] + #2[2]*#3[2] + #3[3]*#3[3]%
readlist#1@vecargs

defveccross#1#2#3% #1 = #2 times #3
bgroup% local definitions
pgfmathsetmacro@x#2[2]*#3[3] - #2[3]*#3[2]%
pgfmathsetmacro@y#2[3]*#3[1] - #2[1]*#3[3]%
pgfmathsetmacro@z#2[1]*#3[2] - #2[2]*#3[1]%
xdef@vecargs@x,@y,@z%
egroup
readlist#1@vecargs
makeatother

begindocument
readlistA1,2,3
readlistB4,5,6

vecaddCAB
C[]

vecsubCAB
C[]

vecdotCAB
C[]

veccrossCAB
C[]
enddocument



SUPPLEMENT



I hope John doesn't mind me (Steven B Segletes) adding his sought-after parser to the code. This allows input of the form vecparseCA+B, vecparseCA - B, vecparseCA .B, and vecparseCA xB (extra spaces of no consequence).



Support added not only for vecparseCA xB, but also vecparseCA x(3,5,6), vecparseC(3,5,6)xB and vecparseC(1,1,1)x(1,2,3).



documentclassarticle
usepackagelistofitems
usepackagepgfmath
usepackageamsmath

makeatletter
newcommand@vecargs% reserve global names

newcommandvecadd
newcommandvecsub
newcommandvecdot
newcommandveccross
newcommandvecparse

defvecadd#1#2#3% #1 = #2 + #3
bgroup% local definitions
pgfmathsetmacro@x#2[1]+#3[1]%
pgfmathsetmacro@y#2[2]+#3[2]%
pgfmathsetmacro@z#2[3]+#3[3]%
xdef@vecargs@x,@y,@z%
egroup
setsepchar,%
readlist#1@vecargs

defvecsub#1#2#3% #1 = #2 - #3
bgroup% local definitions
pgfmathsetmacro@x#2[1]-#3[1]%
pgfmathsetmacro@y#2[2]-#3[2]%
pgfmathsetmacro@z#2[3]-#3[3]%
xdef@vecargs@x,@y,@z%
egroup
setsepchar,%
readlist#1@vecargs

defvecdot#1#2#3% #1 = #2 cdot #3
pgfmathsetmacro@vecargs#2[1]*#3[1] + #2[2]*#3[2] + #3[3]*#3[3]%
setsepchar,%
readlist#1@vecargs

defveccross#1#2#3% #1 = #2 times #3
bgroup% local definitions
pgfmathsetmacro@x#2[2]*#3[3] - #2[3]*#3[2]%
pgfmathsetmacro@y#2[3]*#3[1] - #2[1]*#3[3]%
pgfmathsetmacro@z#2[1]*#3[2] - #2[2]*#3[1]%
xdef@vecargs@x,@y,@z%
egroup
setsepchar,%
readlist#1@vecargs

defvecparse#1#2%
setsepcharx%
readlist*@findop#2%
ifnumlistlen@findop[1]=1relax
itemtomacro@findop[1]tmpA
else
itemtomacro@findop[1,2]tmpF
setsepchar,%
readlisttmpEtmpF%
deftmpAtmpE%
fi
ifnumlistlen@findop[2]=1relax
itemtomacro@findop[2]tmpB
else
itemtomacro@findop[2,2]tmpD
setsepchar,%
readlisttmpCtmpD%
deftmpBtmpC%
fi
if+@findopsep[1]relax
deftmpvecadd#1%
elseif-@findopsep[1]relax
deftmpvecsub#1%
elseif.@findopsep[1]relax
deftmpvecdot#1%
elseif x@findopsep[1]relax
deftmpveccross#1%
fifififi
expandafterexpandafterexpandaftertmpexpandaftertmpAtmpB

makeatother

begindocument
readlistA1,2,3
readlistB4,5,6

vecaddCAB
C[]

VP:vecparseCA+B
C[]

vecsubCAB
C[]

VP:vecparseCA - B
C[]

vecdotCAB
C[]

VP:vecparseCA .B
C[]

veccrossCAB
C[]

VP:vecparseCA xB
C[]

VP:vecparseCA x(3,5,6)
C[]

VP:vecparseC(3,5,6)xB
C[]

VP:vecparseC(1,1,1)x(1,2,3)
C[]

enddocument


enter image description here






share|improve this answer















Just for fun, I wrote routines for 3D vector addition, subtraction, cross product and dot product (scalar treated as a 1D vector). I was trying to actually parse expressions of the form A+B but eventually gave up.



documentclassarticle
usepackagelistofitems
usepackagepgfmath
usepackageamsmath

makeatletter
newcommand@vecargs% reserve global names

newcommandvecadd
newcommandvecsub
newcommandvecdot
newcommandveccross
newcommandvecparse

defvecadd#1#2#3% #1 = #2 + #3
bgroup% local definitions
pgfmathsetmacro@x#2[1]+#3[1]%
pgfmathsetmacro@y#2[2]+#3[2]%
pgfmathsetmacro@z#2[3]+#3[3]%
xdef@vecargs@x,@y,@z%
egroup
readlist#1@vecargs

defvecsub#1#2#3% #1 = #2 - #3
bgroup% local definitions
pgfmathsetmacro@x#2[1]-#3[1]%
pgfmathsetmacro@y#2[2]-#3[2]%
pgfmathsetmacro@z#2[3]-#3[3]%
xdef@vecargs@x,@y,@z%
egroup
readlist#1@vecargs

defvecdot#1#2#3% #1 = #2 cdot #3
pgfmathsetmacro@vecargs#2[1]*#3[1] + #2[2]*#3[2] + #3[3]*#3[3]%
readlist#1@vecargs

defveccross#1#2#3% #1 = #2 times #3
bgroup% local definitions
pgfmathsetmacro@x#2[2]*#3[3] - #2[3]*#3[2]%
pgfmathsetmacro@y#2[3]*#3[1] - #2[1]*#3[3]%
pgfmathsetmacro@z#2[1]*#3[2] - #2[2]*#3[1]%
xdef@vecargs@x,@y,@z%
egroup
readlist#1@vecargs
makeatother

begindocument
readlistA1,2,3
readlistB4,5,6

vecaddCAB
C[]

vecsubCAB
C[]

vecdotCAB
C[]

veccrossCAB
C[]
enddocument



SUPPLEMENT



I hope John doesn't mind me (Steven B Segletes) adding his sought-after parser to the code. This allows input of the form vecparseCA+B, vecparseCA - B, vecparseCA .B, and vecparseCA xB (extra spaces of no consequence).



Support added not only for vecparseCA xB, but also vecparseCA x(3,5,6), vecparseC(3,5,6)xB and vecparseC(1,1,1)x(1,2,3).



documentclassarticle
usepackagelistofitems
usepackagepgfmath
usepackageamsmath

makeatletter
newcommand@vecargs% reserve global names

newcommandvecadd
newcommandvecsub
newcommandvecdot
newcommandveccross
newcommandvecparse

defvecadd#1#2#3% #1 = #2 + #3
bgroup% local definitions
pgfmathsetmacro@x#2[1]+#3[1]%
pgfmathsetmacro@y#2[2]+#3[2]%
pgfmathsetmacro@z#2[3]+#3[3]%
xdef@vecargs@x,@y,@z%
egroup
setsepchar,%
readlist#1@vecargs

defvecsub#1#2#3% #1 = #2 - #3
bgroup% local definitions
pgfmathsetmacro@x#2[1]-#3[1]%
pgfmathsetmacro@y#2[2]-#3[2]%
pgfmathsetmacro@z#2[3]-#3[3]%
xdef@vecargs@x,@y,@z%
egroup
setsepchar,%
readlist#1@vecargs

defvecdot#1#2#3% #1 = #2 cdot #3
pgfmathsetmacro@vecargs#2[1]*#3[1] + #2[2]*#3[2] + #3[3]*#3[3]%
setsepchar,%
readlist#1@vecargs

defveccross#1#2#3% #1 = #2 times #3
bgroup% local definitions
pgfmathsetmacro@x#2[2]*#3[3] - #2[3]*#3[2]%
pgfmathsetmacro@y#2[3]*#3[1] - #2[1]*#3[3]%
pgfmathsetmacro@z#2[1]*#3[2] - #2[2]*#3[1]%
xdef@vecargs@x,@y,@z%
egroup
setsepchar,%
readlist#1@vecargs

defvecparse#1#2%
setsepcharx%
readlist*@findop#2%
ifnumlistlen@findop[1]=1relax
itemtomacro@findop[1]tmpA
else
itemtomacro@findop[1,2]tmpF
setsepchar,%
readlisttmpEtmpF%
deftmpAtmpE%
fi
ifnumlistlen@findop[2]=1relax
itemtomacro@findop[2]tmpB
else
itemtomacro@findop[2,2]tmpD
setsepchar,%
readlisttmpCtmpD%
deftmpBtmpC%
fi
if+@findopsep[1]relax
deftmpvecadd#1%
elseif-@findopsep[1]relax
deftmpvecsub#1%
elseif.@findopsep[1]relax
deftmpvecdot#1%
elseif x@findopsep[1]relax
deftmpveccross#1%
fifififi
expandafterexpandafterexpandaftertmpexpandaftertmpAtmpB

makeatother

begindocument
readlistA1,2,3
readlistB4,5,6

vecaddCAB
C[]

VP:vecparseCA+B
C[]

vecsubCAB
C[]

VP:vecparseCA - B
C[]

vecdotCAB
C[]

VP:vecparseCA .B
C[]

veccrossCAB
C[]

VP:vecparseCA xB
C[]

VP:vecparseCA x(3,5,6)
C[]

VP:vecparseC(3,5,6)xB
C[]

VP:vecparseC(1,1,1)x(1,2,3)
C[]

enddocument


enter image description here







share|improve this answer














share|improve this answer



share|improve this answer








edited 9 hours ago









Steven B. Segletes

160k9205413




160k9205413










answered yesterday









John KormyloJohn Kormylo

46.3k22672




46.3k22672












  • That is really nice.

    – Steven B. Segletes
    yesterday











  • I hope you don't mind my edit.

    – Steven B. Segletes
    yesterday






  • 1





    I was thinking more of expressions like A+(4,5,6) which are a lot easier when A expands to 1,2,3 directly.

    – John Kormylo
    11 hours ago






  • 1





    @marmot I think it would be possible, but would require quite a bit more effort. Any time the input is allowed to be in a free format, requiring sub-evaluations of the components that can than comprise larger components...well a more careful approach is required.

    – Steven B. Segletes
    9 hours ago






  • 1





    @marmot It would likely require an approach like tex.stackexchange.com/questions/332012/…, where an order of operations hierarchy is established, and the input parsed along those lines. But rather than just typesetting the result, vector mechanics needs to be performed.

    – Steven B. Segletes
    8 hours ago

















  • That is really nice.

    – Steven B. Segletes
    yesterday











  • I hope you don't mind my edit.

    – Steven B. Segletes
    yesterday






  • 1





    I was thinking more of expressions like A+(4,5,6) which are a lot easier when A expands to 1,2,3 directly.

    – John Kormylo
    11 hours ago






  • 1





    @marmot I think it would be possible, but would require quite a bit more effort. Any time the input is allowed to be in a free format, requiring sub-evaluations of the components that can than comprise larger components...well a more careful approach is required.

    – Steven B. Segletes
    9 hours ago






  • 1





    @marmot It would likely require an approach like tex.stackexchange.com/questions/332012/…, where an order of operations hierarchy is established, and the input parsed along those lines. But rather than just typesetting the result, vector mechanics needs to be performed.

    – Steven B. Segletes
    8 hours ago
















That is really nice.

– Steven B. Segletes
yesterday





That is really nice.

– Steven B. Segletes
yesterday













I hope you don't mind my edit.

– Steven B. Segletes
yesterday





I hope you don't mind my edit.

– Steven B. Segletes
yesterday




1




1





I was thinking more of expressions like A+(4,5,6) which are a lot easier when A expands to 1,2,3 directly.

– John Kormylo
11 hours ago





I was thinking more of expressions like A+(4,5,6) which are a lot easier when A expands to 1,2,3 directly.

– John Kormylo
11 hours ago




1




1





@marmot I think it would be possible, but would require quite a bit more effort. Any time the input is allowed to be in a free format, requiring sub-evaluations of the components that can than comprise larger components...well a more careful approach is required.

– Steven B. Segletes
9 hours ago





@marmot I think it would be possible, but would require quite a bit more effort. Any time the input is allowed to be in a free format, requiring sub-evaluations of the components that can than comprise larger components...well a more careful approach is required.

– Steven B. Segletes
9 hours ago




1




1





@marmot It would likely require an approach like tex.stackexchange.com/questions/332012/…, where an order of operations hierarchy is established, and the input parsed along those lines. But rather than just typesetting the result, vector mechanics needs to be performed.

– Steven B. Segletes
8 hours ago





@marmot It would likely require an approach like tex.stackexchange.com/questions/332012/…, where an order of operations hierarchy is established, and the input parsed along those lines. But rather than just typesetting the result, vector mechanics needs to be performed.

– Steven B. Segletes
8 hours ago

















draft saved

draft discarded
















































Thanks for contributing an answer to TeX - LaTeX Stack Exchange!


  • Please be sure to answer the question. Provide details and share your research!

But avoid


  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2ftex.stackexchange.com%2fquestions%2f482518%2fhow-one-can-write-a-nice-vector-parser-something-that-does-pgfvecparse-a-b%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

Wikipedia:Vital articles Мазмуну Biography - Өмүр баян Philosophy and psychology - Философия жана психология Religion - Дин Social sciences - Коомдук илимдер Language and literature - Тил жана адабият Science - Илим Technology - Технология Arts and recreation - Искусство жана эс алуу History and geography - Тарых жана география Навигация менюсу

Club Baloncesto Breogán Índice Historia | Pavillón | Nome | O Breogán na cultura popular | Xogadores | Adestradores | Presidentes | Palmarés | Historial | Líderes | Notas | Véxase tamén | Menú de navegacióncbbreogan.galCadroGuía oficial da ACB 2009-10, páxina 201Guía oficial ACB 1992, páxina 183. Editorial DB.É de 6.500 espectadores sentados axeitándose á última normativa"Estudiantes Junior, entre as mellores canteiras"o orixinalHemeroteca El Mundo Deportivo, 16 setembro de 1970, páxina 12Historia do BreogánAlfredo Pérez, o último canoneiroHistoria C.B. BreogánHemeroteca de El Mundo DeportivoJimmy Wright, norteamericano do Breogán deixará Lugo por ameazas de morteResultados de Breogán en 1986-87Resultados de Breogán en 1990-91Ficha de Velimir Perasović en acb.comResultados de Breogán en 1994-95Breogán arrasa al Barça. "El Mundo Deportivo", 27 de setembro de 1999, páxina 58CB Breogán - FC BarcelonaA FEB invita a participar nunha nova Liga EuropeaCharlie Bell na prensa estatalMáximos anotadores 2005Tempada 2005-06 : Tódolos Xogadores da Xornada""Non quero pensar nunha man negra, mais pregúntome que está a pasar""o orixinalRaúl López, orgulloso dos xogadores, presume da boa saúde económica do BreogánJulio González confirma que cesa como presidente del BreogánHomenaxe a Lisardo GómezA tempada do rexurdimento celesteEntrevista a Lisardo GómezEl COB dinamita el Pazo para forzar el quinto (69-73)Cafés Candelas, patrocinador del CB Breogán"Suso Lázare, novo presidente do Breogán"o orixinalCafés Candelas Breogán firma el mayor triunfo de la historiaEl Breogán realizará 17 homenajes por su cincuenta aniversario"O Breogán honra ao seu fundador e primeiro presidente"o orixinalMiguel Giao recibiu a homenaxe do PazoHomenaxe aos primeiros gladiadores celestesO home que nos amosa como ver o Breo co corazónTita Franco será homenaxeada polos #50anosdeBreoJulio Vila recibirá unha homenaxe in memoriam polos #50anosdeBreo"O Breogán homenaxeará aos seus aboados máis veteráns"Pechada ovación a «Capi» Sanmartín e Ricardo «Corazón de González»Homenaxe por décadas de informaciónPaco García volve ao Pazo con motivo do 50 aniversario"Resultados y clasificaciones""O Cafés Candelas Breogán, campión da Copa Princesa""O Cafés Candelas Breogán, equipo ACB"C.B. Breogán"Proxecto social"o orixinal"Centros asociados"o orixinalFicha en imdb.comMario Camus trata la recuperación del amor en 'La vieja música', su última película"Páxina web oficial""Club Baloncesto Breogán""C. B. Breogán S.A.D."eehttp://www.fegaba.com

What should I write in an apology letter, since I have decided not to join a company after accepting an offer letterShould I keep looking after accepting a job offer?What should I do when I've been verbally told I would get an offer letter, but still haven't gotten one after 4 weeks?Do I accept an offer from a company that I am not likely to join?New job hasn't confirmed starting date and I want to give current employer as much notice as possibleHow should I address my manager in my resignation letter?HR delayed background verification, now jobless as resignedNo email communication after accepting a formal written offer. How should I phrase the call?What should I do if after receiving a verbal offer letter I am informed that my written job offer is put on hold due to some internal issues?Should I inform the current employer that I am about to resign within 1-2 weeks since I have signed the offer letter and waiting for visa?What company will do, if I send their offer letter to another company