Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/371.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 轮换及;将文本绘制到直线(x1、y1、x2、y2)时转换值(使用p5.js,处理…atan2)_Javascript_Processing_P5.js - Fatal编程技术网

Javascript 轮换及;将文本绘制到直线(x1、y1、x2、y2)时转换值(使用p5.js,处理…atan2)

Javascript 轮换及;将文本绘制到直线(x1、y1、x2、y2)时转换值(使用p5.js,处理…atan2),javascript,processing,p5.js,Javascript,Processing,P5.js,当我把文字画成直线,并用θ旋转时 这篇课文离行很远。 我认为,原因是依赖于翻译,但我不知道如何修复它。 这是我的代码(p5.js) 我想把这段文字改得紧贴线条 我为这个问题苦苦挣扎了五天。 在几乎不了解θ和切线等之后, 坚持这一步让我对下一步不耐烦。。。请帮忙 此处放置文本的基本思想是,您希望转换到线条/形状上的精确点,然后旋转并放置文本,例如,您可以执行以下操作,将旋转后的文本放置在线条的开头: //Translate to the start of the line translate(

当我把文字画成直线,并用θ旋转时 这篇课文离行很远。 我认为,原因是依赖于翻译,但我不知道如何修复它。 这是我的代码(p5.js)

我想把这段文字改得紧贴线条

我为这个问题苦苦挣扎了五天。 在几乎不了解θ和切线等之后,
坚持这一步让我对下一步不耐烦。。。请帮忙

此处放置文本的基本思想是,您希望转换到线条/形状上的精确点,然后旋转并放置文本,例如,您可以执行以下操作,将旋转后的文本放置在线条的开头:

//Translate to the start of the line
translate(x, y);
//rotate to the desired angle (for example 20)
rotate(20);
//place the text at the start of the line
text("A", 0, 0);
如果希望文字位于直线/形状上的特定点,可以执行一些三角运算以找到精确点,然后使用这些点进行平移:

//Translate to a point on the line before you rotate
translate(linePointX, linePointY);
//rotate to the desired angle (for example 20)
rotate(20);
//place the text at 0,0 (the point of the last translate)
//or increase/decrease the x and y vaues to offset the text
text("A", 0, 0);

此处放置文本的基本思想是,您希望转换到线条/形状上的精确点,然后旋转并放置文本,例如,您可以执行以下操作,将旋转后的文本放置在线条的起点:

//Translate to the start of the line
translate(x, y);
//rotate to the desired angle (for example 20)
rotate(20);
//place the text at the start of the line
text("A", 0, 0);
如果希望文字位于直线/形状上的特定点,可以执行一些三角运算以找到精确点,然后使用这些点进行平移:

//Translate to a point on the line before you rotate
translate(linePointX, linePointY);
//rotate to the desired angle (for example 20)
rotate(20);
//place the text at 0,0 (the point of the last translate)
//or increase/decrease the x and y vaues to offset the text
text("A", 0, 0);

注意:我发现放置文本时最简单的方法是平移到直线上的一个点(不是x,y起点),然后应用旋转,然后将文本放置在“0,0”,因为位置已由平移和旋转设置。你需要做一点三角学来计算线下的距离,你需要得到x和y坐标来进行平移。你救了我,非常感谢!文本(“A”,0,0,)有效@Sorifind您应该将其作为答案发布,以便其他人投票/接受/轻易发现。注意:我发现放置文本时最简单的方法是将文本平移到直线上的一个点(不是x,y起点),然后应用旋转,然后将文本放置在“0,0”,因为位置已由平移和旋转设置。你需要做一点三角学来计算线下的距离,你需要得到x和y坐标来进行平移。你救了我,非常感谢!文本(“A”,0,0,)有效@Sorifind你应该把它作为一个答案贴出来,这样别人就可以投票/接受/很容易发现它