Forgot password?
 Register account
View 249|Reply 3

[几何] quadratic bezier curve

[Copy link]

3159

Threads

7941

Posts

610K

Credits

Credits
63770
QQ

Show all posts

hbghlyj Posted 2023-3-10 00:47 |Read mode
从$P_{1}(x_{1},y_{1})$到$P_{2}(x_{2},y_{2})$画一条抛物线, 使其在$P_1,P_2$的切线的交点为$S(x,y)$
抛物线方程为$\begin{cases}x={\frac {m_{2}x_{2}-m_{1}x_{1}-(y_{2}-y_{1})}{m_{2}-m_{1}}}\\y=y_{i}+m_{i}(x-x_{i});\quad (i=1,2\,{\hbox{ gives same solution}})\end{cases}$
其中$m_1,m_2$分别为$SP_1,SP_2$的斜率.

3159

Threads

7941

Posts

610K

Credits

Credits
63770
QQ

Show all posts

 Author| hbghlyj Posted 2023-3-10 00:48
Last edited by hbghlyj 2023-3-10 02:31绘制一个带有波浪形顶部的矩形


Catenaries of Constant Length
悬链线具有以下奇怪的特性:两点之间的悬链线的长度等于这两点之间的悬链线下方的面积。
证明非常简单:\[\sqrt{1 +\left(\frac{d}{dx} \cosh(x) \right)^2} = \sqrt{1 + \sinh^2(x)} = \cosh(x)\]
现在对等式两端在区间 $[a,b]$ 上积分。注意前一个积分给出的是$a$和$b$之间$\cosh x$的弧长,后面的积分给出的是$a$和$b$之间$\cosh x$图象下的面积。画出长度相同的悬链线。
方程
$$\frac{y}{a}=\cosh \frac{x}{a}-1$$
使用$\ln$表示$\arccosh$得
\[
\left\{
\begin{aligned}
v & = \sqrt{L^2+a^2}-a, \\
u&=\frac{L^{2}-v^{2}}{2 v} \ln \frac{L+v}{L-v}\end{aligned} \right.
\]计算cubic Bezier curve控制点
\[\left\{
\begin{aligned}
\text{m1}&=0\\
\text{m2} & =\sinh\frac{u}{a}
\end{aligned} \right.
\]



将picture环境转换为TikZ

3159

Threads

7941

Posts

610K

Credits

Credits
63770
QQ

Show all posts

 Author| hbghlyj Posted 2023-3-10 07:53

qbezier.java

Graphics in LaTeX2ε Appendix A
The Java program started with the line java qbezier x1 y1 m1 x2 y2 m2 writes a file qbezier.tex which can be pasted into a picture environment, whence it draws the desired curve.
  1. import java.io.*;
  2. class qbezier {
  3. static void main(String[] args) {
  4. if(args.length != 6) {
  5. System.out.println("Gebrauch: java qbezier x1 y1 m1 x2 y2 m2");
  6. return;
  7. }
  8. File outfile = new File("qbezier.tex");
  9. try {
  10. double x1 = Double.parseDouble(args[0]);
  11. double y1 = Double.parseDouble(args[1]);
  12. double m1 = Double.parseDouble(args[2]);
  13. double x2 = Double.parseDouble(args[3]);
  14. double y2 = Double.parseDouble(args[4]);
  15. double m2 = Double.parseDouble(args[5]);
  16. if(m1 == m2) {
  17. System.out.println("Keine Auswertung mglich:");
  18. System.out.println("m1 und m2 mssen verschieden sein");
  19. return;
  20. }
  21. String outstring = "% qbezier P1=("+x1+"/"+y1+") m1="+m1+" P2=("+x2+"/"+y2+") m2="+m2;
  22. outstring += "\n\\qbezier";
  23. double x = (m2*x2-m1*x1+y1-y2) / (m2-m1);
  24. double u = y1+m1*(x-x1);
  25. double v = y2+m2*(x-x2);
  26. double y = 0.5*(u+v);
  27. outstring += "(" + runde(x1) + ", " + runde(y1) + ")";
  28. outstring += "(" + runde(x) + ", " + runde(y) + ")";
  29. outstring += "(" + runde(x2) + ", " + runde(y2) + ")";
  30. FileWriter out = new FileWriter(outfile.getPath(), false);
  31. out.write(outstring);
  32. out.close();
  33. }
  34. catch(NumberFormatException e) {
  35. System.out.println("Eingabe nicht korrekt");
  36. System.out.println("Korrekte Eingabe: x1 y1 m1 x2 y2 m2");
  37. }
  38. catch(IOException e) {
  39. }
  40. }
  41. static String runde(double t) {
  42. String s = "";
  43. int T = (int)(Math.round(10000 * t));
  44. double d = T/10000.0;
  45. s = String.valueOf(d);
  46. return s;
  47. }
  48. }
Copy the Code

3159

Threads

7941

Posts

610K

Credits

Credits
63770
QQ

Show all posts

 Author| hbghlyj Posted 2023-3-10 08:21
hbghlyj 发表于 2023-3-9 17:48
将picture环境转换为TikZ
虽然看上去差不多, 检查SVG发现,
picture生成的SVG的曲线是由很多点拼成的TikZ把1条cubic bezier转换为SVG的1条cubic bezier
Screenshot 2023-03-09 at 22-29-07 Untitled7 - Jupyter Notebook.png Screenshot 2023-03-09 at 22-29-07 Untitled7 - Jupyter Notebook.png

说明TikZ比picture更好

Mobile version|Discuz Math Forum

2025-5-31 11:21 GMT+8

Powered by Discuz!

× Quick Reply To Top Edit