Debian Codegraph @

texmf-dist/doc/latex/tkz-elements/TKZdoc-elements-classes-occs.tex

raw
1 \newpage
2 \section{Class \tkzClass{occs}}
3 \label{sec:orthonormal_cartesian_coordinate_system}
4
5 \subsection{Description}
6 The \texttt{occs} class models an \emph{orthonormal Cartesian coordinate system} (OCCS). Its primary use is to transition from the default coordinate system to one aligned with geometric features of the figure (e.g., a directrix, a major axis, or the vertex of a conic).
7
8 All calculations in this package are performed in a fixed OCCS. For convenience and clarity, this class allows defining and transforming to a new OCCS using a direction (a line) and a new origin point.
9
10 \medskip
11
12 The typical use case is to simplify the coordinates of geometric objects such as conics, by aligning the axes with their natural directions.
13
14 \subsection{Creating an occs}\label{occs:create}
15
16 An OCCS (orthonormal Cartesian coordinate system) is defined by:
17 \begin{itemize}
18 \item a line, which sets the direction of the new \emph{ordinate} axis (the $y$-axis), and
19 \item a point, which becomes the new origin.
20 \end{itemize}
21
22 The abscissa axis (the $x$-axis) is automatically computed to be orthogonal to the ordinate axis, ensuring a right-handed coordinate system.
23
24 \medskip
25
26 There are two equivalent ways to create an OCCS:
27
28 \begin{mybox}
29 \code{O.S = occs(L.axis, z.S)} \hfill (short form, recommended)
30 \\
31 \code{O.S = occs:new(L.axis, z.S)} \hfill (explicit constructor)
32 \end{mybox}
33
34 The result is stored in the table \code{O} under the key \code{"S"}, representing the OCCS centered at point \code{z.S}.
35
36 \medskip
37
38 This object can then be used to:
39 \begin{itemize}
40 \item compute coordinates of points in the new system,
41 \item project points onto the new axes, or
42 \item reconstruct geometric elements aligned with the new frame.
43 \end{itemize}
44
45
46 The new abscissa axis is automatically computed to ensure orthonormality.
47
48 \subsection{Attributes of an occs}
49
50 \bgroup
51 \catcode`_=12
52 \small
53 \captionof{table}{Attributes of an \texttt{occs} object.}\label{occs:attributes}
54 \begin{tabular}{ll}
55 \toprule
56 \texttt{Attribute} & \textbf{Description} \\
57 \midrule
58 \tkzAttr{occs}{type} & Object type name, always \texttt{"occs"} \\
59 \tkzAttr{occs}{origin} & The new origin point \\
60 \tkzAttr{occs}{x} & Point that defines the new $x$-axis (abscissa) \\
61 \tkzAttr{occs}{y} & Point that defines the new $y$-axis (ordinate) \\
62 \tkzAttr{occs}{abscissa} & Line representing the abscissa axis \\
63 \tkzAttr{occs}{ordinate} & Line representing the ordinate axis \\
64 \bottomrule
65 \end{tabular}
66 \egroup
67
68
69
70 \subsubsection{Example: attributes of \texttt{occs}}
71 \label{ssub:example_attributes_of_occs}
72
73 A few words about the arguments of a new OCCS. The most important is the line that defines the direction of the new ordinate axis. For a parabola, this direction should point from the directrix to the focus. For a hyperbola or an ellipse, it should go from the center to the principal focus. The orientation is determined by the order of the two points used to construct the line: it runs from the first to the second.
74
75 If this line is constructed as an orthogonal to another line (as in the example below), then its orientation depends on the orientation of the original line.
76 \vspace{1em}
77
78 \begin{verbatim}
79 \directlua{
80 init_elements()
81 z.O = point(0, 0)
82 z.i = point(1, 0)
83 z.j = point(0, 1)
84 z.A = point(-1, -1)
85 z.B = point(4, 2)
86 L.AB = line(z.A, z.B)
87 z.S = point(0, 3)
88 L.axis = L.AB:ortho_from(z.S)
89 % new occs
90 O.S = occs(L.axis, z.S)
91 z.u = O.S.x
92 z.v = O.S.y
93 z.ax = O.S.abscissa.pa
94 z.bx = O.S.ordinate.pa
95 z.ay = O.S.abscissa.pb
96 z.by = O.S.ordinate.pb}
97 \begin{tikzpicture}
98 \tkzGetNodes
99 \tkzDrawLines(A,B)
100 \tkzDrawLines[purple,add=4 and 4](ax,ay bx,by)
101 \tkzDrawSegments[->,red,thick](O,i O,j)
102 \tkzDrawSegments[->,purple,thick](S,u S,v)
103 \tkzLabelSegment[below,sloped,pos=.9](A,B){L.AB the directrix}
104 \tkzLabelSegment[below,sloped,pos=3](ax,ay){abscissa}
105 \tkzLabelSegment[below,sloped,pos=5](bx,by){ordinate major\_axis}
106 \tkzLabelPoints(O,S)
107 \tkzLabelPoints[left](j,v)
108 \tkzLabelPoints[below right](i,u)
109 \end{tikzpicture}
110 \end{verbatim}
111
112
113 \directlua{
114 init_elements()
115 z.O = point(0, 0)
116 z.i = point(1, 0)
117 z.j = point(0, 1)
118 z.A = point(-1, -1)
119 z.B = point(4, 2)
120 L.AB = line(z.A, z.B)
121 z.S = point(0, 3)
122 L.axis = L.AB:ortho_from(z.S)
123 % new occs
124 O.S = occs(L.axis, z.S)
125 z.u = O.S.x
126 z.v = O.S.y
127 z.ax = O.S.abscissa.pa
128 z.bx = O.S.ordinate.pa
129 z.ay = O.S.abscissa.pb
130 z.by = O.S.ordinate.pb}
131
132 \begin{center}
133 \begin{tikzpicture}
134 \tkzGetNodes
135 \tkzDrawLines(A,B)
136 \tkzDrawLines[purple,add=4 and 4](ax,ay bx,by)
137 \tkzDrawSegments[->,red,thick](O,i O,j)
138 \tkzDrawSegments[->,purple,thick](S,u S,v)
139 \tkzLabelSegment[below,sloped,pos=.9](A,B){L.AB the directrix}
140 \tkzLabelSegment[below,sloped,pos=3](ax,ay){abscissa}
141 \tkzLabelSegment[below,sloped,pos=5](bx,by){ordinate major\_axis}
142 \tkzLabelPoints(O,S)
143 \tkzLabelPoints[left](j,v)
144 \tkzLabelPoints[below right](i,u)
145 \end{tikzpicture}
146 \end{center}
147
148 \subsection{Methods of the class \texttt{occs}}
149
150 This class provides the following methods:
151
152 \bgroup
153 \small
154 \captionof{table}{occs methods.}\label{occs:methods}
155 \begin{tabular}{ll}
156 \toprule
157 \textbf{Methods} & \texttt{Reference} \\
158 \midrule
159 \texttt{Constructor} & \\
160 \midrule
161 \tkzMeth{occs}{occs(dir, origin)} & \ref{ssub:example_attributes_of_occs}] \\
162 \midrule
163 \texttt{Methods Returning a Real Number} & \\
164 \midrule
165 \tkzMeth{occs}{coordinates(pt)} & [\ref{occs:coordinates}] \\
166 \bottomrule
167 \end{tabular}
168 \egroup
169
170 \subsection{Method \tkzMeth{occs}{occs(L, pt)}}
171 \label{occs:new}
172
173 The general creation of an orthonormal coordinate system attached to a line has already been presented
174 [see \ref{occs:create}].
175
176 Here we emphasize the important role of the two points defining the line~\(L\).
177 If these points are swapped, the resulting coordinate system is not the same:
178 the orientation of the axes is reversed. In every case, the system is oriented in the
179 forward direction, following the order of the defining points.
180
181
182 \begin{tkzexample}[latex=.5\textwidth]
183 \directlua{%
184 z.O = point(0, 0)
185 z.A = point(0, 1)
186 z.B = point(4, 2)
187 z.S = point(1, 3)
188 L.AB = line(z.A, z.B)
189 z.K = L.AB:projection(z.S)
190 O.sys = occs(L.AB, z.S)
191 z.u, z.v = O.sys.x, O.sys.y}
192 \begin{tikzpicture}
193 \tkzGetNodes
194 \tkzDrawLines[purple](A,B)
195 \tkzDrawPoints(A,B,S,O,K)
196 \tkzLabelPoints(A,B,S,O,K,u,v)
197 \tkzDrawSegments[thick,->](S,u S,v)
198 \end{tikzpicture}
199 \end{tkzexample}
200
201 \begin{tkzexample}[latex=.5\textwidth]
202 \directlua{%
203 z.O = point(0, 0)
204 z.A = point(0, 1)
205 z.B = point(4, 2)
206 z.S = point(1, 3)
207 L.AB = line(z.B, z.A)
208 z.K = L.AB:projection(z.S)
209 O.sys = occs(L.AB, z.S)
210 z.u, z.v = O.sys.x, O.sys.y}
211 \begin{tikzpicture}
212 \tkzGetNodes
213 \tkzDrawLines[purple](A,B)
214 \tkzDrawPoints(A,B,S,O,K)
215 \tkzLabelPoints(A,B,S,O,K,u,v)
216 \tkzDrawSegments[thick,->](S,u S,v)
217 \end{tikzpicture}
218 \end{tkzexample}
219
220 \subsection{Method \tkzMeth{occs}{coordinates(pt)}}\label{occs:coordinates}
221 We want to construct the parabola passing through three given points,
222 knowing that the axis of symmetry of the parabola is parallel to a given line \((MN)\).
223
224 \begin{enumerate}
225 \item First, we must check that the three points \(A,B,C\) are not collinear,
226 and that no two of them lie on the same line perpendicular to \((MN)\).
227 \item Next, we define a reference system
228 \((M,\overrightarrow{MU},\overrightarrow{MV})\) attached to the line \((MN)\).
229 \item In this new system, there exists a unique parabola through the three points.
230 The function \tkzFct{tkz}{parabola(pt, pt, pt)}
231 [see \ref{tkz:parabola}] computes the coefficients of the quadratic function
232 \(y = Ax^2 + Bx + C\).
233 \item To apply this function, we need the coordinates of \(A,B,C\) in the new system.
234 This is exactly the role of the method
235 \tkzMeth{occs}{coordinates(pt)}.
236 \end{enumerate}
237
238 \directlua{
239 z.O = point(0, 0)
240 z.A = point(-1.5, 1)
241 z.B = point(1, 0.25)
242 z.C = point(2.5, 1.8)
243 z.M = point(3, 0)
244 z.N = point(2, 1)
245 L.MN = line(z.M, z.N)
246 sys = occs(L.MN, z.M)
247 z.U = sys.x
248 z.V = sys.y
249 L.MV = line(z.M, z.V)
250 L.MU = line(z.M, z.U)
251 local a, b, c = tkz.parabola(point(sys:coordinates(z.A)),
252 point(sys:coordinates(z.B)),
253 point(sys:coordinates(z.C)))
254 function f(x)
255 return a * x ^ 2 + b * x + c
256 end
257
258 xf = - b / (2 * a)
259 yf = (4 * a * c - b ^ 2 + 1) / (4 * a)
260 xk = xf
261 yk = (4 * a * c - (b ^ 2) - 1) / (4 * a)
262 z.K = L.MV:report(yk, L.MU:report(xk))
263 z.f = L.MU:report(xf)
264 z.F = L.MV:report(yf, z.f)
265 L.dir = L.MU:ll_from(z.K)
266 PA = conic(z.F, L.dir, 1)
267 curve = PA:points(-3, 3, 30)
268 }
269 \begin{tikzpicture}
270 \tkzGetNodes
271 \tkzDrawSegments[->,purple,thick](M,U M,V)
272 \tkzDrawLines(M,N)
273 \tkzDrawCoordinates[smooth,red,thick](curve)
274 \tkzDrawPoints(A,B,C)
275 \tkzLabelPoints(A,B,U,V)
276 \tkzLabelPoints[above](M,N,C)
277 \end{tikzpicture}
278
279 \subsection{Example: Using \texttt{occs} with a parabola}
280
281 Let us consider a practical example. Suppose we want to compute the intersection points between a parabola and a line. The parabola is defined by its directrix and focus. In a coordinate system centered at the vertex $S$ of the parabola, with the $x$-axis parallel to the directrix and passing through $S$, the equation of the parabola becomes
282 \[
283 y = \frac{x^2}{2p}
284 \]
285 where $p$ is the \emph{latus rectum}, i.e., the distance from the focus to the directrix.
286
287 \vspace{1em}
288
289 To determine the intersection points, we first express the equation of the given line in the new coordinate system. Then, we solve the equation system using $y = \frac{x^2}{2p}$. Internally, this is handled using two utility functions.
290
291 \vspace{1em}
292
293 If solutions exist, the result consists of two values $r_1$ and $r_2$, which are the abscissas of the intersection points in the new OCCS. Once the corresponding ordinates are computed, we can either:
294 \begin{itemize}
295 \item express the coordinates in \TIKZ{} directly using a projection onto the new OCCS, or
296 \item geometrically reconstruct the points: for each $r$, find the corresponding point $x$ on the new $x$-axis (\code{OCCS.abscissa}), and use it to locate the point on the parabola.
297 \end{itemize}
298
299 \vspace{1em}
300 \begin{verbatim}
301 \directlua{
302 init_elements()
303 z.O = point(0, 0)
304 z.i = point(1, 0)
305 z.j = point(0, 1)
306 z.A = point(-1, 0)
307 z.B = point(5, 4)
308 L.dir = line(z.A, z.B)
309 z.F = point(0, 3)
310 CO.parabola = conic(z.F, L.dir, 1)
311 PA.curve = CO.parabola:points(-3, 3, 50)
312 local p = CO.parabola.p
313 z.P = L.dir:report(p, z.K)
314 z.X = PA:point(p)
315 z.H = L.dir:projection(z.X)
316 z.K = CO.parabola.K
317 z.S = CO.parabola.vertex
318 L.KF = CO.parabola.major_axis
319 % new occs
320 O.SKF = occs(L.KF, z.S)
321 z.u = O.SKF.x
322 z.v = O.SKF.y
323 % line a,b
324 z.a = point(-1, 1)
325 z.b = point(3, 5)
326 L.ab = line(z.a, z.b)
327 % % coordinates in the new occs
328 X, Y = O.SKF:coordinates(z.F)
329 Xa, Ya = O.SKF:coordinates(z.a)
330 Xb, Yb = O.SKF:coordinates(z.b)
331 % solve in the new occs
332 local r, s = tkz.line_coefficients(Xa, Ya, Xb, Yb)
333 r1, r2 = solve_para_line(p, r, s)
334 z.x = O.SKF.abscissa:report(r1, z.K)
335 z.y = O.SKF.abscissa:report(r2, z.K)
336 L1 = L.dir:ortho_from(z.x)
337 L2 = L.dir:ortho_from(z.y)
338 z.s1 = intersection(L.ab, L1)
339 z.s2 = intersection(L.ab, L2)}
340
341 \begin{tikzpicture}
342 \tkzGetNodes
343 \tkzDrawCoordinates[smooth,orange,thick](PA.curve)
344 \tkzDrawLines(A,B)
345 \tkzDrawLines[add = 1 and 1](K,F)
346 \tkzDrawSegments[add = .5 and .5,blue](a,b)
347 \tkzDrawSegments[dashed](s1,x s2,y)
348 \tkzDrawPoints(A,B,F,K,S)
349 \tkzDrawPoints[blue,size=2](a,b)
350 \tkzDrawPoints[blue,size=2](s1,s2,x,y)
351 \tkzLabelPoints[blue](a,b)
352 \tkzLabelPoints[blue,above left](s1,s2)
353 \tkzLabelPoints(O,i,u,S,A,B,x,y)
354 \tkzLabelPoints[left](j,v)
355 \tkzLabelPoints[right](F,K)
356 \tkzDrawSegments[->,red,thick](O,i O,j)
357 \tkzDrawSegments[->,purple,thick](S,u S,v)
358 \tkzLabelSegment[below,sloped,pos=.7](A,B){Directrix}
359 \end{tikzpicture}
360 \end{verbatim}
361
362 \directlua{
363 init_elements()
364 z.O = point(0, 0)
365 z.i = point(1, 0)
366 z.j = point(0, 1)
367 z.A = point(-1, 0)
368 z.B = point(5, 4)
369 L.dir = line(z.A, z.B)
370 z.F = point(0, 3)
371 CO.parabola = conic(z.F, L.dir, 1)
372 PA.curve = CO.parabola:points(-3, 3, 50)
373 local p = CO.parabola.p
374 z.P = L.dir:report(p, z.K)
375 z.X = CO.parabola:point(p)
376 z.H = L.dir:projection(z.X)
377 z.K = CO.parabola.K
378 z.S = CO.parabola.vertex
379 L.KF = CO.parabola.major_axis
380 % new occs
381 O.SKF = occs(L.KF, z.S)
382 z.u = O.SKF.x
383 z.v = O.SKF.y
384 % line a,b
385 z.a = point(-1, 1)
386 z.b = point(3, 5)
387 L.ab = line(z.a, z.b)
388 % % coordinates in the new occs
389 X, Y = O.SKF:coordinates(z.F)
390 Xa, Ya = O.SKF:coordinates(z.a)
391 Xb, Yb = O.SKF:coordinates(z.b)
392 % solve in the new occs
393 local r, s = tkz.line_coefficients(Xa, Ya, Xb, Yb)
394 r1, r2 = tkz.solve_quadratic_(1, -2 * p * r, -2 * p * s)
395 z.x = O.SKF.abscissa:report(r1, z.K)
396 z.y = O.SKF.abscissa:report(r2, z.K)
397 local L1 = L.dir:ortho_from(z.x)
398 local L2 = L.dir:ortho_from(z.y)
399 z.s1 = intersection(L.ab, L1)
400 z.s2 = intersection(L.ab, L2)}
401
402 \begin{center}
403 \begin{tikzpicture}
404 \tkzGetNodes
405 \tkzDrawCoordinates[smooth,orange,thick](PA.curve)
406 \tkzDrawLines(A,B)
407 \tkzDrawLines[add = 1 and 1](K,F)
408 \tkzDrawSegments[add = .5 and .5,blue](a,b)
409 \tkzDrawSegments[dashed](s1,x s2,y)
410 \tkzDrawPoints(A,B,F,K,S)
411 \tkzDrawPoints[blue,size=2](a,b)
412 \tkzDrawPoints[blue,size=2](s1,s2,x,y)
413 \tkzLabelPoints[blue](a,b)
414 \tkzLabelPoints[blue,above left](s1,s2)
415 \tkzLabelPoints(O,i,u,S,A,B,x,y)
416 \tkzLabelPoints[left](j,v)
417 \tkzLabelPoints[right](F,K)
418 \tkzDrawSegments[->,red,thick](O,i O,j)
419 \tkzDrawSegments[->,purple,thick](S,u S,v)
420 \tkzLabelSegment[below,sloped,pos=.7](A,B){Directrix}
421 \end{tikzpicture}
422 \end{center}
423 \endinput