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?
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
add a comment |
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
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
add a comment |
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
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
tikz-pgf tikzmark
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
add a comment |
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
add a comment |
2 Answers
2
active
oldest
votes
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

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
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
@ferahfezamargin = 3.14159mmwicked!
– 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
|
show 7 more comments
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

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 likeA+(4,5,6)which are a lot easier when A expands to1,2,3directly.
– 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
|
show 6 more comments
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
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
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

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
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
@ferahfezamargin = 3.14159mmwicked!
– 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
|
show 7 more comments
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

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
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
@ferahfezamargin = 3.14159mmwicked!
– 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
|
show 7 more comments
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

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

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
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
@ferahfezamargin = 3.14159mmwicked!
– 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
|
show 7 more comments
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
@ferahfezamargin = 3.14159mmwicked!
– 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
|
show 7 more comments
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

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 likeA+(4,5,6)which are a lot easier when A expands to1,2,3directly.
– 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
|
show 6 more comments
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

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 likeA+(4,5,6)which are a lot easier when A expands to1,2,3directly.
– 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
|
show 6 more comments
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

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

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 likeA+(4,5,6)which are a lot easier when A expands to1,2,3directly.
– 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
|
show 6 more comments
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 likeA+(4,5,6)which are a lot easier when A expands to1,2,3directly.
– 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
|
show 6 more comments
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.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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
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