找回密码
 快速注册
搜索
楼主: abababa

tikzjax 能脱离服务器用吗?

[复制链接]

413

主题

1558

回帖

1万

积分

积分
11498

显示全部楼层

 楼主| abababa 发表于 2021-11-17 14:45

AoPS 测试

回复 69# kuing

原来如此。我还是看以前的那个改的,也没记清具体怎么写,就照记忆抄下来了。因为我是在html文件里试验的,也没有这个符号,所以也不知道错在哪。

730

主题

1万

回帖

9万

积分

积分
93593
QQ

显示全部楼层

kuing 发表于 2021-11-17 14:47
回复 70# abababa

49# 的第三个图弹不出框,原因应该是代码里面有 ' 影响了,咋改哩?

413

主题

1558

回帖

1万

积分

积分
11498

显示全部楼层

 楼主| abababa 发表于 2021-11-17 15:07
回复 71# kuing

是的,我也发现了,52楼的那个因为有一个B',带一个撇号,就显示不了。
能不能在tikz_str那里,把这个撇也替换一下,换成不常用的符号,比如换成汉字'撇',然后在显示的函数里,再换回来。我猜这样可以。
  1. var tikz_str=encodeURI(str);
复制代码
在上面这句之后加一个:
  1. tikz_str=tikz_str.replace('\'','撇');
复制代码
然后显示的时候,把那个
  1. decodeURI(tikz_code)
复制代码
换成
  1. decodeURI(tikz_code).replace('撇','\'');
复制代码

730

主题

1万

回帖

9万

积分

积分
93593
QQ

显示全部楼层

kuing 发表于 2021-11-17 15:36
回复 72# abababa

嗯,我改成了
  1.         var tikz_str=encodeURI(str);
  2.         tikz_str=tikz_str.replace(/\'/g,'撇');
复制代码
以及
  1.         tikz_window.innerHTML='<div><a href="javascript:;" class="float_close" onclick="close_tikz_window();">关闭</a></div><div><textarea style="width:99%;height:300px;">'+decodeURI(tikz_code).replace(/撇/g,'\'')+'</textarea></div>';
复制代码
用 /.../g 是匹配全局

413

主题

1558

回帖

1万

积分

积分
11498

显示全部楼层

 楼主| abababa 发表于 2021-11-17 15:41
回复 73# kuing
原来如此,我都是看网友写的/img,猜到是有什么功能,也没去查,就照着抄,有时还忘记加。
这回带撇号的能正确显示了。不知道会不会遇到其它问题。

730

主题

1万

回帖

9万

积分

积分
93593
QQ

显示全部楼层

kuing 发表于 2021-11-17 15:44
话说,帖子的 主楼 是
  1. <div class="postmessage firstpost">
复制代码
回帖是
  1. <div class="postmessage ">
复制代码
(postmessage 后面带空格)
尽管如此
  1. document.getElementsByClassName('postmessage');
复制代码
都能把它们选中,我也是今天才知道……

730

主题

1万

回帖

9万

积分

积分
93593
QQ

显示全部楼层

kuing 发表于 2021-11-17 16:17
用同样的方法让 code 里的 [ tikz ] 避开替换,在开头先用
  1. let blockcodes = document.getElementsByClassName('blockcode');
  2. for (let item of blockcodes)
  3.     {
  4.     item.innerHTML = item.innerHTML
  5.     .replace(/\[tikz\]/g,'随便字符1')
  6.     .replace(/\[\/tikz\]/g,'随便字符2');
  7.     };
复制代码
显示完之后再还原回来
  1. for (let item of blockcodes)
  2.     {
  3.     item.innerHTML = item.innerHTML
  4.     .replace(/随便字符1/g,'[tikz]')
  5.     .replace(/随便字符2/g,'[/tikz]');
  6.     };
复制代码
实际当中我取 随便字符1、2 分别是 tikz_begin 和 tikz_end,现在无法将它写到 code 里面,因为它们就会被替换掉,所以只能像现在这样表达……

730

主题

1万

回帖

9万

积分

积分
93593
QQ

显示全部楼层

kuing 发表于 2021-11-17 16:43
我按照自己搭建了CORS proxy.好像成功了.示例如下:可以跨域请求.它的输出是aops的网页. ...
hbghlyj 发表于 2021-11-16 21:51
这个到底是怎么玩嘀?你可以在你的论坛上示范一下嘛?

3149

主题

8386

回帖

6万

积分

$\style{scale:11;fill:#eff}꩜$

积分
65391
QQ

显示全部楼层

hbghlyj 发表于 2021-11-17 20:31
回复 77# kuing
我先注册了Heroku帐号,下载了git和Heroku CLI,把cors-anywhere仓库克隆到本地,然后cd cors-anywhere,然后npm install,然后heroku login登录,然后heroku create新建应用,然后把本地的文件push到master上就可以用了
使用的时候就在那个herokuapp域名后面加上想要跨域请求的域名就可以了

730

主题

1万

回帖

9万

积分

积分
93593
QQ

显示全部楼层

kuing 发表于 2021-11-19 16:51
回复 79# hbghlyj

这个太复杂,我还是懒得弄了 /emmm

730

主题

1万

回帖

9万

积分

积分
93593
QQ

显示全部楼层

kuing 发表于 2021-11-19 17:03
这回带撇号的能正确显示了。不知道会不会遇到其它问题。
abababa 发表于 2021-11-17 15:41
论坛上连续 >=2 个空格会变成 &nbsp; 所以还得多做一步将它们替换为空格。
先前如果写
  1. [tikz]\begin{tikzpicture}
  2. \draw       sin(1,1)cos(2,0)sin(3,-1)cos(4,0);
  3. \end{tikzpicture}[/tikz]
复制代码
是会出问题的,现在也 OK 了。

(你自己的测试文件应该不存在这个问题)

另外,我用类似方法弄了 svg 的支持,而且不用写 [svg][/svg],直接贴 svg 代码即可。
例:
  1. <svg width="700" height="160" xmlns="http://www.w3.org/2000/svg">
  2. <rect x="10" y="10" width="140" height="140" rx="5" ry="5"
  3.       style="fill:lightgrey">
  4.    <set attributeName="fill" from="lightgrey" to="red"
  5.          begin="mouseover" end="mouseout"/>
  6. </rect>
  7. <text x="200" y="75" font-size="30">Move over me and click
  8.    <set attributeName="font-size" from="30" to="35"
  9.          begin="mouseover" end="mouseout"/>
  10.    <set attributeName="fill" from="black" to="red"
  11.          begin="mousedown" end="mouseup"/>
  12. </text>
  13. </svg>
复制代码
显示:
<svg width="700" height="160" xmlns="http://www.w3.org/2000/svg">
<rect x="10" y="10" width="140" height="140" rx="5" ry="5"
      style="fill:lightgrey">
   <set attributeName="fill" from="lightgrey" to="red"
         begin="mouseover" end="mouseout"/>
</rect>
<text x="200" y="75" font-size="30">Move over me and click
   <set attributeName="font-size" from="30" to="35"
         begin="mouseover" end="mouseout"/>
   <set attributeName="fill" from="black" to="red"
         begin="mousedown" end="mouseup"/>
</text>
</svg>
弹窗口就不弄了。

(已废除)

3149

主题

8386

回帖

6万

积分

$\style{scale:11;fill:#eff}꩜$

积分
65391
QQ

显示全部楼层

hbghlyj 发表于 2021-11-19 20:55
本帖最后由 hbghlyj 于 2022-2-22 18:31 编辑 css的transform有一个matrix3d,这个应该是最为强大的了.下面的介绍来自drafts.csswg.org/css-transforms-2/#mathematical-description.
• Mathematically, all transform functions can be represented as 4x4 transformation matrices of the following form:
\begin{bmatrix} m11 & m21 & m31 & m41 \\ m12 & m22 & m32 & m42 \\ m13 & m23 & m33 & m43 \\ m14 & m24 & m34 & m44 \end{bmatrix}
One translation unit on a matrix is equivalent to 1 pixel in the local coordinate system of the element.
• A 3D translation with the parameters tx, ty and tz is equivalent to the matrix:
\begin{bmatrix} 1 & 0 & 0 & tx \\ 0 & 1 & 0 & ty \\ 0 & 0 & 1 & tz \\ 0 & 0 & 0 & 1 \end{bmatrix}
• A 3D scaling with the parameters sx, sy and sz is equivalent to the matrix:
\begin{bmatrix} sx & 0 & 0 & 0 \\ 0 & sy & 0 & 0 \\ 0 & 0 & sz & 0 \\ 0 & 0 & 0 & 1 \end{bmatrix}
• A 3D rotation with the vector [x,y,z] and the parameter alpha is equivalent to the matrix:
\begin{bmatrix} 1 - 2 \cdot (y^2 + z^2) \cdot sq & 2 \cdot (x \cdot y \cdot sq - z \cdot sc) & 2 \cdot (x \cdot z \cdot sq + y \cdot sc) & 0 \\ 2 \cdot (x \cdot y \cdot sq + z \cdot sc) & 1 - 2 \cdot (x^2 + z^2) \cdot sq & 2 \cdot (y \cdot z \cdot sq - x \cdot sc) & 0 \\ 2 \cdot (x \cdot z \cdot sq - y \cdot sc) & 2 \cdot (y \cdot z \cdot sq + x \cdot sc) & 1 - 2 \cdot (x^2 + y^2) \cdot sq & 0 \\ 0 & 0 & 0 & 1 \end{bmatrix}
where$$sc = \sin (\alpha/2) \cdot \cos (\alpha/2)$$$$sq = \sin^2 (\alpha/2)$$and where x, y, and z have been normalized (that is, where the x, y, and z values given have been divided by the square root of the sum of their squares).
在计算两个4×4矩阵的插值的时候使用了四元数,而不是欧拉角,以避免环架锁定(Gimbal Locks)的问题
13.1.1. Decomposing a 3D matrix
The pseudo code below is based upon the "unmatrix" method in "Graphics Gems II, edited by Jim Arvo", but modified to use Quaternions instead of Euler angles to avoid the problem of Gimbal Locks.

The following pseudocode works on a 4x4 homogeneous matrix:

Input:  matrix      ; a 4x4 matrix
Output: translation ; a 3 component vector
        scale       ; a 3 component vector
        skew        ; skew factors XY,XZ,YZ represented as a 3 component vector
        perspective ; a 4 component vector
        quaternion  ; a 4 component vector
Returns false if the matrix cannot be decomposed, true if it can


// Normalize the matrix.
if (matrix[3][3] == 0)
    return false

for (i = 0; i < 4; i++)
    for (j = 0; j < 4; j++)
        matrix[i​][j] /= matrix[3][3]

// perspectiveMatrix is used to solve for perspective, but it also provides
// an easy way to test for singularity of the upper 3x3 component.
perspectiveMatrix = matrix

for (i = 0; i < 3; i++)
    perspectiveMatrix[i​][3] = 0

perspectiveMatrix[3][3] = 1

if (determinant(perspectiveMatrix) == 0)
    return false

// First, isolate perspective.
if (matrix[0][3] != 0 || matrix[1][3] != 0 || matrix[2][3] != 0)
    // rightHandSide is the right hand side of the equation.
    rightHandSide[0] = matrix[0][3]
    rightHandSide[1] = matrix[1][3]
    rightHandSide[2] = matrix[2][3]
    rightHandSide[3] = matrix[3][3]

    // Solve the equation by inverting perspectiveMatrix and multiplying
    // rightHandSide by the inverse.
    inversePerspectiveMatrix = inverse(perspectiveMatrix)
    transposedInversePerspectiveMatrix = transposeMatrix4(inversePerspectiveMatrix)
    perspective = multVecMatrix(rightHandSide, transposedInversePerspectiveMatrix)
else
    // No perspective.
    perspective[0] = perspective[1] = perspective[2] = 0
    perspective[3] = 1

// Next take care of translation
for (i = 0; i < 3; i++)
    translate[i​] = matrix[3][i​]

// Now get scale and shear. 'row' is a 3 element array of 3 component vectors
for (i = 0; i < 3; i++)
    row[i​][0] = matrix[i​][0]
    row[i​][1] = matrix[i​][1]
    row[i​][2] = matrix[i​][2]

// Compute X scale factor and normalize first row.
scale[0] = length(row[0])
row[0] = normalize(row[0])

// Compute XY shear factor and make 2nd row orthogonal to 1st.
skew[0] = dot(row[0], row[1])
row[1] = combine(row[1], row[0], 1.0, -skew[0])

// Now, compute Y scale and normalize 2nd row.
scale[1] = length(row[1])
row[1] = normalize(row[1])
skew[0] /= scale[1];

// Compute XZ and YZ shears, orthogonalize 3rd row
skew[1] = dot(row[0], row[2])
row[2] = combine(row[2], row[0], 1.0, -skew[1])
skew[2] = dot(row[1], row[2])
row[2] = combine(row[2], row[1], 1.0, -skew[2])

// Next, get Z scale and normalize 3rd row.
scale[2] = length(row[2])
row[2] = normalize(row[2])
skew[1] /= scale[2]
skew[2] /= scale[2]

// At this point, the matrix (in rows) is orthonormal.
// Check for a coordinate system flip.  If the determinant
// is -1, then negate the matrix and the scaling factors.
pdum3 = cross(row[1], row[2])
if (dot(row[0], pdum3) < 0)
    for (i = 0; i < 3; i++)
        scale[i​] *= -1;
        row[i​][0] *= -1
        row[i​][1] *= -1
        row[i​][2] *= -1

// Now, get the rotations out
quaternion[0] = 0.5 * sqrt(max(1 + row[0][0] - row[1][1] - row[2][2], 0))
quaternion[1] = 0.5 * sqrt(max(1 - row[0][0] + row[1][1] - row[2][2], 0))
quaternion[2] = 0.5 * sqrt(max(1 - row[0][0] - row[1][1] + row[2][2], 0))
quaternion[3] = 0.5 * sqrt(max(1 + row[0][0] + row[1][1] + row[2][2], 0))

if (row[2][1] > row[1][2])
    quaternion[0] = -quaternion[0]
if (row[0][2] > row[2][0])
    quaternion[1] = -quaternion[1]
if (row[1][0] > row[0][1])
    quaternion[2] = -quaternion[2]

return true
13.1.2. Interpolation of decomposed 3D matrix values
Each component of the decomposed values translation, scale, skew and perspective of the source matrix get linearly interpolated with each corresponding component of the destination matrix.

Note: For instance, translate[0] of the source matrix and translate[0] of the destination matrix are interpolated numerically, and the result is used to set the translation of the animating element.

Quaternions of the decomposed source matrix are interpolated with quaternions of the decomposed destination matrix using the spherical linear interpolation (Slerp) as described by the pseudo code below:

Input:  quaternionA   ; a 4 component vector
        quaternionB   ; a 4 component vector
        t             ; interpolation parameter with 0 <= t <= 1
Output: quaternionDst ; a 4 component vector


product = dot(quaternionA, quaternionB)

// Clamp product to -1.0 <= product <= 1.0
product = min(product, 1.0)
product = max(product, -1.0)

if (abs(product) == 1.0)
   quaternionDst = quaternionA
   return

theta = acos(product)
w = sin(t * theta) / sqrt(1 - product * product)

for (i = 0; i < 4; i++)
  quaternionA[i​] *= cos(t * theta) - product * w
  quaternionB[i​] *= w
  quaternionDst[i​] = quaternionA[i​] + quaternionB[i​]

return
13.1.3. Recomposing to a 3D matrix
After interpolation, the resulting values are used to transform the elements user space. One way to use these values is to recompose them into a 4x4 matrix. This can be done following the pseudo code below:

Input:  translation ; a 3 component vector
        scale       ; a 3 component vector
        skew        ; skew factors XY,XZ,YZ represented as a 3 component vector
        perspective ; a 4 component vector
        quaternion  ; a 4 component vector
Output: matrix      ; a 4x4 matrix

Supporting functions (matrix is a 4x4 matrix):
  matrix  multiply(matrix a, matrix b)   returns the 4x4 matrix product of a * b

// apply perspective
for (i = 0; i < 4; i++)
  matrix[i​][3] = perspective[i​]

// apply translation
for (i = 0; i < 4; i++)
  for (j = 0; j < 3; j++)
    matrix[3][i​] += translation[j] * matrix[j][i​]

// apply rotation
x = quaternion[0]
y = quaternion[1]
z = quaternion[2]
w = quaternion[3]

// Construct a composite rotation matrix from the quaternion values
// rotationMatrix is a identity 4x4 matrix initially
rotationMatrix[0][0] = 1 - 2 * (y * y + z * z)
rotationMatrix[0][1] = 2 * (x * y - z * w)
rotationMatrix[0][2] = 2 * (x * z + y * w)
rotationMatrix[1][0] = 2 * (x * y + z * w)
rotationMatrix[1][1] = 1 - 2 * (x * x + z * z)
rotationMatrix[1][2] = 2 * (y * z - x * w)
rotationMatrix[2][0] = 2 * (x * z - y * w)
rotationMatrix[2][1] = 2 * (y * z + x * w)
rotationMatrix[2][2] = 1 - 2 * (x * x + y * y)

matrix = multiply(matrix, rotationMatrix)

// apply skew
// temp is a identity 4x4 matrix initially
if (skew[2])
    temp[2][1] = skew[2]
    matrix = multiply(matrix, temp)

if (skew[1])
    temp[2][1] = 0
    temp[2][0] = skew[1]
    matrix = multiply(matrix, temp)

if (skew[0])
    temp[2][0] = 0
    temp[1][0] = skew[0]
    matrix = multiply(matrix, temp)

// apply scale
for (i = 0; i < 3; i++)
  for (j = 0; j < 4; j++)
    matrix[i​][j] *= scale[i​]

return

730

主题

1万

回帖

9万

积分

积分
93593
QQ

显示全部楼层

kuing 发表于 2021-11-20 02:16
回复 82# hbghlyj

切换到非全屏风格就盖不住你原来的头像了

3149

主题

8386

回帖

6万

积分

$\style{scale:11;fill:#eff}꩜$

积分
65391
QQ

显示全部楼层

hbghlyj 发表于 2021-12-16 05:57
本帖最后由 hbghlyj 于 2021-12-20 14:48 编辑 在页面上直接嵌入svg有一个弊端:
如果页面上有多个svg,且有相同的id,就会冲突,比如
  1. <svg><defs><g id="st1"><circle style="fill:inherit" r="10"/></g></defs><use x="50" y="10" xlink:href="#st1" /></svg>
  2. <svg><filter id="st1"><feGaussianBlur stdDeviation="5"/></filter><circle cx="60" cy="60" r="50" fill="green" /><circle cx="170" cy="60" r="50" fill="green" filter="url(#st1)" /></svg>
复制代码
另外,如果svg中带有style标签的话,多个svg所定义的css也可能冲突.
尤其是用软件作图,比如Adobe illustrator,inkscape等等,生成的svg的id都是按一种规则来编号,如果页面上多个svg的话互相之间冲突.
能否把svg和主文档分开,避免多个svg之间冲突.


欧拉角,环架锁定

730

主题

1万

回帖

9万

积分

积分
93593
QQ

显示全部楼层

kuing 发表于 2021-12-16 14:15
回复 84# hbghlyj

测试完能不能编辑回正常,现在每次打开这个页面就要下载一个东西,以及出现了个不知什么画面……

413

主题

1558

回帖

1万

积分

积分
11498

显示全部楼层

 楼主| abababa 发表于 2022-6-4 22:18
本帖最后由 abababa 于 2022-6-5 21:17 编辑
abababa 发表于 2021-10-3 09:36
回复 27# kuing

果然如此,那还是不用其它软件导出,直接写tikz代码方便。要是这个能用tkz-euclide就更好 ...

$type tkz.zip (7.45 KB, 下载次数: 3)

这个tkz-euclide的,maven今天给我了,我试了一个能行。他更新了一个又发给我了,再传一下。有了这个挺方便的,方便画平面几何图。

我使用中遇到的问题:
1.忘了给下标加{},后来才想起来
2.画中点的那个函数是tkzDefMidPoint('A','B')('C'),开始把'A','B'写在一起,写成'A,B'了,改过来就能用了
3.直线和圆的交点,一般有两个,但哪个先哪个后不确定,真tikz里可能也是不确定的,以前写的代码,要是交点不正确,可能要把这个顺序改一下才行

暂时发现这么多。

413

主题

1558

回帖

1万

积分

积分
11498

显示全部楼层

 楼主| abababa 发表于 2022-6-9 15:14
hbghlyj 发表于 2022-6-9 12:25
建议放到GitHub上

查了一下,好像是专门存放代码的?

145

主题

241

回帖

2295

积分

积分
2295

显示全部楼层

郝酒 发表于 2022-6-15 15:31
本帖最后由 郝酒 于 2022-6-15 15:51 编辑

我也来凑个热闹:)

145

主题

241

回帖

2295

积分

积分
2295

显示全部楼层

郝酒 发表于 2022-6-25 22:17
点一下公式或者svg,弹出TeX代码或Tikz代码,好高级呀。是怎么做到的呢?

15

主题

958

回帖

1万

积分

积分
12454

显示全部楼层

色k 发表于 2022-6-26 01:35
郝酒 发表于 2022-6-25 22:17
点一下公式或者svg,弹出TeX代码或Tikz代码,好高级呀。是怎么做到的呢?

目前只是针对用 [tikz] 标签所贴的 tikz 图点击显示 tikz 而已,对公式及 svg 并无此功能。

实现的方法本帖就有讨论到,你也可以查看本页面源代码,找到 zdy3.js,打开看具体代码。
这名字我喜欢

手机版|悠闲数学娱乐论坛(第3版)

GMT+8, 2025-3-4 07:17

Powered by Discuz!

× 快速回复 返回顶部 返回列表