by topsquark » Wed Aug 23, 2023 4:28 am
Thank you so much, both of you. I understand what's been said so far.
I have added to the code a bit. I can state my eventual goal, now that the preliminaries are out of the way. I have just
one little problem left.
What I want to do is determine the quadrant of a point, whether given in coordinates or
as a coordinate. I need to distinguish if I'm looking at (X) or (\x,\y), respectively. Now, from an earlier question, I've actually learned how to do this. I can create a new pair of commands: point and coords, that will take care of that. What I need to do is structure the command "quadrant" to take the form:
\quadrant{point}{X}{}
or
\quadrant{coords}{3}{2}
I've even set this up already. (See the code below.) (Note: to print out the three possibles, I've added an extra argument to \quadrant to print out a dot on the correct line.)
My problem is this. In order for the command quadrant to use either point or coords, I have to put the "if" statement inside a scope. Now, I can do anything I want inside the scope (I've currently got it printing a red dot if I'm using point and a blue dot if I'm using coords), but I need to define \x and \y depending on which option is being used. But if I'm inside the scope, I lose that information when I end the scope.
To be more precise:
I have a subroutine to use to get the x,y coordinates from X, so if I'm using point I do that.
If I'm using coords, I already have the x,y coordinates and I just set them to be \x = x and \y = y.
But I lose this information once I pass outside the scope, so the coordinates \x and \y are undefined when I try to find the quadrant. (newcommand\q{...}). I need to "hard save" the macro values \x and \y.
I know (somewhere on the net) I've seen a solution to this problem, but I don't recall where or how to do it.
Any suggestions?
Thanks!
-Dan
Code: Select all
Code, edit and compile here:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
הההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההה
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
Run LaTeX here
Thank you so much, both of you. I understand what's been said so far. I have added to the code a bit. I can state my eventual goal, now that the preliminaries are out of the way. I have just [i]one[/i] little problem left. What I want to do is determine the quadrant of a point, whether given in coordinates or [i]as[/i] a coordinate. I need to distinguish if I'm looking at (X) or (\x,\y), respectively. Now, from an earlier question, I've actually learned how to do this. I can create a new pair of commands: point and coords, that will take care of that. What I need to do is structure the command "quadrant" to take the form: \quadrant{point}{X}{} or \quadrant{coords}{3}{2} I've even set this up already. (See the code below.) (Note: to print out the three possibles, I've added an extra argument to \quadrant to print out a dot on the correct line.) My problem is this. In order for the command quadrant to use either point or coords, I have to put the "if" statement inside a scope. Now, I can do anything I want inside the scope (I've currently got it printing a red dot if I'm using point and a blue dot if I'm using coords), but I need to define \x and \y depending on which option is being used. But if I'm inside the scope, I lose that information when I end the scope. To be more precise: I have a subroutine to use to get the x,y coordinates from X, so if I'm using point I do that. If I'm using coords, I already have the x,y coordinates and I just set them to be \x = x and \y = y. But I lose this information once I pass outside the scope, so the coordinates \x and \y are undefined when I try to find the quadrant. (newcommand\q{...}). I need to "hard save" the macro values \x and \y. I know (somewhere on the net) I've seen a solution to this problem, but I don't recall where or how to do it. Any suggestions? Thanks! -Dan [code] \documentclass{article} \usepackage{tikz} \begin{document} \newif\ifpoint \tikzset{ point/.code={\pointtrue} } \newif\ifcoords \tikzset{ coords/.code={\coordstrue} } \newcommand\quadrant[4]{ \begin{scope}[#1] \ifpoint \fill[red] (0,-#4) circle(2pt); \fi \ifcoords \fill[blue] (0,-#4) circle(2pt); \fi \end{scope} \def\x{#2} \def\y{#3} \pgfmathsetmacro\q{ \ifdim\x > 0pt \ifdim\y > 0pt 1 \else \ifdim\y < 0pt 4 \fi \fi \else \ifdim\x < 0pt \ifdim\y > 0pt 2 \else \ifdim\y < 0pt 3 \fi \fi \fi \fi } } \begin{tikzpicture} \quadrant{coords}{3pt}{-2pt}{0}; \node[anchor=west] at (0.5,0) {The point (3,-2) is in Quadrant \q.}; \quadrant{point}{4pt}{1pt}{1}; \node[anchor=west] at (0.5,-1) {The point (4,1) is in Quadrant \q.}; \quadrant{coords}{-5pt}{-1pt}{2}; \node[anchor=west] at (0.5,-2) {The point (-5,-1) is in Quadrant \q.}; \end{tikzpicture} \end{document} [/code]