如何在具有渐近线的曲面上绘制矢量?

如何在具有渐近线的曲面上绘制矢量?

这是我目前的代码:

import three;
import math;

texpreamble("\usepackage{bm}");
texpreamble("\newcommand{\ex}{\bm{e}_x}");
texpreamble("\newcommand{\ey}{\bm{e}_y}");
texpreamble("\newcommand{\ez}{\bm{e}_z}");
texpreamble("\newcommand{\av}{\bm{a}}");
texpreamble("\newcommand{\Ri}[1]{\bm{\vec{R}_{#1}}}");

size(300,0);

pen thickp=linewidth(2mm);
real rho=1, phi=60, z=0.8;

currentprojection=perspective((4,1,2));

real r=1.1;
pen p=black;
draw(Label("$\ex$",1.1),O--r*X,p,Arrow3); // x unit vector
draw(Label("$\ey$",1.1),O--r*Y,p,Arrow3); // y unit vector
draw(Label("$\ez$",1.1),O--r*Z,p,Arrow3); // z unit vector

triple R0=(-1,-3,-4); // vector R0 to cable
triple a=(0,1,0); // direction
draw(Label("$\av$",0.65),(R0-a/2)--(R0+a/2),red,Arrow3);
draw("$\Ri{0}$",R0--O,align=2*dir(90,phi),Arrow3,DotMargin3);

我想要实现类似于蓝色表面上的红色箭头的效果:表面上的箭头。表面应位于由 $a$ 和 $\vec{R_0}$ 创建的平面中。新箭头应从坐标轴的原点开始,并且该箭头的矢量分量应投影在 $e_x、e_y$ 和 $e_z$ 上。

我找不到这样的例子,而且我是一个渐近线新手。

答案1

这就是我最终得到的结果(主要感谢 Alan Bromborsky 的帮助):

import three;
import math;

texpreamble("\usepackage{bm}");
texpreamble("\newcommand{\ex}{\bm{e}_x}");
texpreamble("\newcommand{\ey}{\bm{e}_y}");
texpreamble("\newcommand{\ez}{\bm{e}_z}");
texpreamble("\newcommand{\av}{\bm\vec{{a}}}");
texpreamble("\newcommand{\Bv}{\bm\vec{{B}}}");
texpreamble("\newcommand{\nv}{\hat{\bm{n}}}");
texpreamble("\newcommand{\Ri}[1]{\bm\vec{{R}_{#1}}}");
texpreamble("\newcommand{\Bi}[1]{\bm\vec{{B}_{#1}}}");

void draw_right_angle(triple a, triple b, triple O, real l=0.25){
    a = l*a/abs(a);
    b = l*b/abs(b);
    draw("",(O+a)--(O+a+b)--(O+b),linewidth(0.25mm)+black);
    return;}

void draw_two_vector_surface(triple a, triple b, triple O,real l=1.4, material m=opacity(0.5)+yellow){
    real lc = l-1;
    a = l*a;
    b = l*b;
    triple ac = lc*a;
    triple bc = lc*b;
    path3 P = (O+a+b)--(O-ac+b)--(O-ac-bc)--(O-bc+a)--cycle;
    draw(surface(P),m,nolight);
    return;}

triple draw_two_vector_vector(triple a, triple b, triple O, real l=0.6){
    a = a/abs(a);
    b = -b/abs(b);
    triple c = l * (a+b);
    draw((O)--(O+c),green,Arrow3);
    return c;}

size(300,0);

pen thickp=linewidth(2mm);
real rho=1, phi=60, z=0.8;

// currentprojection=orthographic((4,1,2));
currentprojection=perspective((4,-2,2));

real r=1.1;
pen p=black;
draw(Label("$\ex$",1.1),O--r*X,p,Arrow3); // x unit vector
draw(Label("$\ey$",1.1),O--r*Y,p,Arrow3); // y unit vector
draw(Label("$\ez$",1.1),O--r*Z,p,Arrow3); // z unit vector

triple R0=(-2,-1,-2); // vector R0 to cable
triple a=(1,0.2,-0.1); // direction
triple n=cross(a,R0);
triple O=(0,0,0);

n = n/abs(n);
draw(Label("$\av$",0.65),(R0-a/2)--(R0+a/2),align=W, red,Arrow3);
draw_right_angle(a,n,R0,0.25);
draw_right_angle(-R0,n,R0,0.25);

draw("$\Ri{0}$",R0--O,align=2*dir(90,phi),Arrow3,DotMargin3);

draw_two_vector_surface(a, R0, O);
triple Bv = draw_two_vector_vector(a, R0, O );
label("$\Bv$", O+Bv, SE, green);

draw("",(O--O+(Bv.x,0,0)), green, Arrow3);
draw("",(O+Bv--O+(Bv.x,0,0)), dashed+green);
label("$\Bi{x}$", O+(Bv.x,0,0),W, green); 

draw("",(O--O+(0,Bv.y,0)), green, Arrow3);
draw("",(O+Bv--O+(0,Bv.y,0)), dashed+green);
label("$\Bi{y}$", O+(0,Bv.y,0),NW*0.4, green); 

draw("",(O--O+(0,0,Bv.z)), green, Arrow3);
draw("",(O+Bv--O+(0,0,Bv.z)), dashed+green);
label("$\Bi{z}$", O+(0,0,Bv.z),W, green); 

在此处输入图片描述

相关内容