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?

Multi tool use
Multi tool use

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







y2,2Lq9Frv5faMSHI0mKuom y
24 fmp L YkR,WIO8XUODgIZj3jJ8S,MTutyaS6bF6 f78c,a,pq6Z4S KfiURCfXu2JJblfqAA4qomRrQr6c6C

Popular posts from this blog

RemoteApp sporadic failureWindows 2008 RemoteAPP client disconnects within a matter of minutesWhat is the minimum version of RDP supported by Server 2012 RDS?How to configure a Remoteapp server to increase stabilityMicrosoft RemoteApp Active SessionRDWeb TS connection broken for some users post RemoteApp certificate changeRemote Desktop Licensing, RemoteAPPRDS 2012 R2 some users are not able to logon after changed date and time on Connection BrokersWhat happens during Remote Desktop logon, and is there any logging?After installing RDS on WinServer 2016 I still can only connect with two users?RD Connection via RDGW to Session host is not connecting

Vilaño, A Laracha Índice Patrimonio | Lugares e parroquias | Véxase tamén | Menú de navegación43°14′52″N 8°36′03″O / 43.24775, -8.60070

Cegueira Índice Epidemioloxía | Deficiencia visual | Tipos de cegueira | Principais causas de cegueira | Tratamento | Técnicas de adaptación e axudas | Vida dos cegos | Primeiros auxilios | Crenzas respecto das persoas cegas | Crenzas das persoas cegas | O neno deficiente visual | Aspectos psicolóxicos da cegueira | Notas | Véxase tamén | Menú de navegación54.054.154.436928256blindnessDicionario da Real Academia GalegaPortal das Palabras"International Standards: Visual Standards — Aspects and Ranges of Vision Loss with Emphasis on Population Surveys.""Visual impairment and blindness""Presentan un plan para previr a cegueira"o orixinalACCDV Associació Catalana de Cecs i Disminuïts Visuals - PMFTrachoma"Effect of gene therapy on visual function in Leber's congenital amaurosis"1844137110.1056/NEJMoa0802268Cans guía - os mellores amigos dos cegosArquivadoEscola de cans guía para cegos en Mortágua, PortugalArquivado"Tecnología para ciegos y deficientes visuales. Recopilación de recursos gratuitos en la Red""Colorino""‘COL.diesis’, escuchar los sonidos del color""COL.diesis: Transforming Colour into Melody and Implementing the Result in a Colour Sensor Device"o orixinal"Sistema de desarrollo de sinestesia color-sonido para invidentes utilizando un protocolo de audio""Enseñanza táctil - geometría y color. Juegos didácticos para niños ciegos y videntes""Sistema Constanz"L'ocupació laboral dels cecs a l'Estat espanyol està pràcticament equiparada a la de les persones amb visió, entrevista amb Pedro ZuritaONCE (Organización Nacional de Cegos de España)Prevención da cegueiraDescrición de deficiencias visuais (Disc@pnet)Braillín, un boneco atractivo para calquera neno, con ou sen discapacidade, que permite familiarizarse co sistema de escritura e lectura brailleAxudas Técnicas36838ID00897494007150-90057129528256DOID:1432HP:0000618D001766C10.597.751.941.162C97109C0155020