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?

Bullying boss launched a smear campaign and made me unemployable

How to compactly explain secondary and tertiary characters without resorting to stereotypes?

Calculating entropy change: reversible vs irreversible process

Valid term from quadratic sequence?

How do conventional missiles fly?

Can my sorcerer use a spellbook only to collect spells and scribe scrolls, not cast?

Unlock My Phone! February 2018

Assassin's bullet with mercury

How could indestructible materials be used in power generation?

How to show a landlord what we have in savings?

How to tell a function to use the default argument values?

Is it acceptable for a professor to tell male students to not think that they are smarter than female students?

How can I deal with my CEO asking me to hire someone with a higher salary than me, a co-founder?

How to prevent "they're falling in love" trope

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

What mechanic is there to disable a threat instead of killing it?

How do I gain back my faith in my PhD degree?

Forgetting the musical notes while performing in concert

Mathematica command that allows it to read my intentions

What is the idiomatic way to say "clothing fits"?

What type of content (depth/breadth) is expected for a short presentation for Asst Professor interview in the UK?

iPad being using in wall mount battery swollen

Why didn't Miles's spider sense work before?

What's the in-universe reasoning behind sorcerers needing material components?



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
    2 days ago











  • Asymptote is a good choice

    – Black Mild
    2 days ago











  • 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
    2 days ago















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
    2 days ago











  • Asymptote is a good choice

    – Black Mild
    2 days ago











  • 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
    2 days ago













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
    2 days ago











  • Asymptote is a good choice

    – Black Mild
    2 days ago











  • 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
    2 days ago

















  • 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
    2 days ago











  • Asymptote is a good choice

    – Black Mild
    2 days ago











  • 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
    2 days ago
















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
2 days ago





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
2 days ago













Asymptote is a good choice

– Black Mild
2 days ago





Asymptote is a good choice

– Black Mild
2 days ago













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
2 days ago





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
2 days ago










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
    2 days ago











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

    – ferahfeza
    2 days ago







  • 1





    @ferahfeza margin = 3.14159mm wicked!

    – L. F.
    2 days ago






  • 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
    2 days ago







  • 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
    2 days 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%
setsepchar%
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
    2 days ago











  • I hope you don't mind my edit.

    – Steven B. Segletes
    2 days ago






  • 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
    yesterday






  • 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
    yesterday






  • 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
    yesterday











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
    2 days ago











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

    – ferahfeza
    2 days ago







  • 1





    @ferahfeza margin = 3.14159mm wicked!

    – L. F.
    2 days ago






  • 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
    2 days ago







  • 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
    2 days ago
















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
    2 days ago











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

    – ferahfeza
    2 days ago







  • 1





    @ferahfeza margin = 3.14159mm wicked!

    – L. F.
    2 days ago






  • 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
    2 days ago







  • 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
    2 days ago














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 2 days ago









Steven B. Segletes

160k9205413




160k9205413










answered 2 days ago









ferahfezaferahfeza

7,35911933




7,35911933












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

    – Steven B. Segletes
    2 days ago











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

    – ferahfeza
    2 days ago







  • 1





    @ferahfeza margin = 3.14159mm wicked!

    – L. F.
    2 days ago






  • 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
    2 days ago







  • 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
    2 days ago


















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

    – Steven B. Segletes
    2 days ago











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

    – ferahfeza
    2 days ago







  • 1





    @ferahfeza margin = 3.14159mm wicked!

    – L. F.
    2 days ago






  • 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
    2 days ago







  • 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
    2 days ago

















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

– Steven B. Segletes
2 days ago





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

– Steven B. Segletes
2 days ago













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

– ferahfeza
2 days ago






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

– ferahfeza
2 days ago





1




1





@ferahfeza margin = 3.14159mm wicked!

– L. F.
2 days ago





@ferahfeza margin = 3.14159mm wicked!

– L. F.
2 days ago




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
2 days ago






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
2 days ago





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
2 days ago






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
2 days 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%
setsepchar%
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
    2 days ago











  • I hope you don't mind my edit.

    – Steven B. Segletes
    2 days ago






  • 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
    yesterday






  • 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
    yesterday






  • 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
    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%
setsepchar%
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
    2 days ago











  • I hope you don't mind my edit.

    – Steven B. Segletes
    2 days ago






  • 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
    yesterday






  • 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
    yesterday






  • 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
    yesterday













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%
setsepchar%
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%
setsepchar%
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 yesterday









Steven B. Segletes

160k9205413




160k9205413










answered 2 days ago









John KormyloJohn Kormylo

46.4k22672




46.4k22672












  • That is really nice.

    – Steven B. Segletes
    2 days ago











  • I hope you don't mind my edit.

    – Steven B. Segletes
    2 days ago






  • 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
    yesterday






  • 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
    yesterday






  • 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
    yesterday

















  • That is really nice.

    – Steven B. Segletes
    2 days ago











  • I hope you don't mind my edit.

    – Steven B. Segletes
    2 days ago






  • 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
    yesterday






  • 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
    yesterday






  • 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
    yesterday
















That is really nice.

– Steven B. Segletes
2 days ago





That is really nice.

– Steven B. Segletes
2 days ago













I hope you don't mind my edit.

– Steven B. Segletes
2 days ago





I hope you don't mind my edit.

– Steven B. Segletes
2 days ago




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
yesterday





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
yesterday




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
yesterday





@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
yesterday




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
yesterday





@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
yesterday

















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

Romeo and Juliet ContentsCharactersSynopsisSourcesDate and textThemes and motifsCriticism and interpretationLegacyScene by sceneSee alsoNotes and referencesSourcesExternal linksNavigation menu"Consumer Price Index (estimate) 1800–"10.2307/28710160037-3222287101610.1093/res/II.5.31910.2307/45967845967810.2307/2869925286992510.1525/jams.1982.35.3.03a00050"Dada Masilo: South African dancer who breaks the rules"10.1093/res/os-XV.57.1610.2307/28680942868094"Sweet Sorrow: Mann-Korman's Romeo and Juliet Closes Sept. 5 at MN's Ordway"the original10.2307/45957745957710.1017/CCOL0521570476.009"Ram Leela box office collections hit massive Rs 100 crore, pulverises prediction"Archived"Broadway Revival of Romeo and Juliet, Starring Orlando Bloom and Condola Rashad, Will Close Dec. 8"Archived10.1075/jhp.7.1.04hon"Wherefore art thou, Romeo? To make us laugh at Navy Pier"the original10.1093/gmo/9781561592630.article.O006772"Ram-leela Review Roundup: Critics Hail Film as Best Adaptation of Romeo and Juliet"Archived10.2307/31946310047-77293194631"Romeo and Juliet get Twitter treatment""Juliet's Nurse by Lois Leveen""Romeo and Juliet: Orlando Bloom's Broadway Debut Released in Theaters for Valentine's Day"Archived"Romeo and Juliet Has No Balcony"10.1093/gmo/9781561592630.article.O00778110.2307/2867423286742310.1076/enst.82.2.115.959510.1080/00138380601042675"A plague o' both your houses: error in GCSE exam paper forces apology""Juliet of the Five O'Clock Shadow, and Other Wonders"10.2307/33912430027-4321339124310.2307/28487440038-7134284874410.2307/29123140149-661129123144728341M"Weekender Guide: Shakespeare on The Drive""balcony"UK public library membership"romeo"UK public library membership10.1017/CCOL9780521844291"Post-Zionist Critique on Israel and the Palestinians Part III: Popular Culture"10.2307/25379071533-86140377-919X2537907"Capulets and Montagues: UK exam board admit mixing names up in Romeo and Juliet paper"Istoria Novellamente Ritrovata di Due Nobili Amanti2027/mdp.390150822329610820-750X"GCSE exam error: Board accidentally rewrites Shakespeare"10.2307/29176390149-66112917639"Exam board apologises after error in English GCSE paper which confused characters in Shakespeare's Romeo and Juliet""From Mariotto and Ganozza to Romeo and Guilietta: Metamorphoses of a Renaissance Tale"10.2307/37323537323510.2307/2867455286745510.2307/28678912867891"10 Questions for Taylor Swift"10.2307/28680922868092"Haymarket Theatre""The Zeffirelli Way: Revealing Talk by Florentine Director""Michael Smuin: 1938-2007 / Prolific dance director had showy career"The Life and Art of Edwin BoothRomeo and JulietRomeo and JulietRomeo and JulietRomeo and JulietEasy Read Romeo and JulietRomeo and Julieteeecb12003684p(data)4099369-3n8211610759dbe00d-a9e2-41a3-b2c1-977dd692899302814385X313670221313670221

Creating closest line along the point''s azimuth using PostgreSQL Planned maintenance scheduled April 17/18, 2019 at 00:00UTC (8:00pm US/Eastern) Announcing the arrival of Valued Associate #679: Cesar Manara Unicorn Meta Zoo #1: Why another podcast?Drawing line between points at specific distance in PostGIS?How to efficiently find the closest point over the dateline?How to find the nearest point by using PostGIS function?PostGIS nearest point with LATERAL JOIN in PostgreSQL 9.3+Creating a table and inserting selected streets using plpgsql functionsCreating a table that stores Distances and other columnSaving select query results (year wise) from PostgreSQL/PostGIS to text filesWhat is the information behind this geometry?How to give start and end vertex ids dynamically in pgr_dijkstra?Point to Polygon nearest distance DS_distance is not using geography index & knn <-> or <#> does not give result in orderLine to point conversion with start point and end point detection?

Crop image to path created in TikZ? Announcing the arrival of Valued Associate #679: Cesar Manara Planned maintenance scheduled April 17/18, 2019 at 00:00UTC (8:00pm US/Eastern)Crop an inserted image?TikZ pictures does not appear in posterImage behind and beyond crop marks?Tikz picture as large as possible on A4 PageTransparency vs image compression dilemmaHow to crop background from image automatically?Image does not cropTikzexternal capturing crop marks when externalizing pgfplots?How to include image path that contains a dollar signCrop image with left size given