- android - 多次调用 OnPrimaryClipChangedListener
- android - 无法更新 RecyclerView 中的 TextView 字段
- android.database.CursorIndexOutOfBoundsException : Index 0 requested, 光标大小为 0
- android - 使用 AppCompat 时,我们是否需要明确指定其 UI 组件(Spinner、EditText)颜色
我在加工草图中有一条线段和一个圆。在草图中,圆找到线段上最近的点,并创建另一条线来显示该最近的点。我希望圆圈穿过这条线向最近的点移动。另外,我希望圆找到线段本身最近的点,但我的草图现在的表现就好像这条线永远持续下去。如有任何帮助,我们将不胜感激。
float x1,y1,x2,y2;
float cx,cy;
float x4,y4;
void setup() {
size(600,600);
}
void init() {
x1 = (int)random(100,500);
y1 = (int)random(100,500);
x2 = (int)random(100,500);
y2 = (int)random(100,500);
cx = (int)random(100,500);
cy = (int)random(100,500);
}
void draw() {
background(60);
init();
stroke(220);
line(x1,y1,x2,y2);
noFill();
ellipse(cx,cy,50,50);
noStroke();
fill(220,20,20);//red- center of circle
ellipse(cx,cy,8,8);
// calculate the point
float k = ((y2-y1) * (cx-x1) - (x2-x1) * (cy-y1)) /
((y2-y1)*(y2-y1) + (x2- x1)*(x2-x1));
float x4 = cx - k * (y2-y1);
float y4 = cy + k * (x2-x1);
fill(20,20,220); //blue - point on line segment
ellipse(x4,y4, 8,8);
stroke(0);
line(cx,cy,x4,y4);
noLoop();
}
void keyPressed() {
loop();
}
最佳答案
如果有两个点,可以使用lerp()
函数来获取它们之间的一系列点。
Calculates a number between two numbers at a specific increment. The
amt
parameter is the amount to interpolate between the two values where 0.0 equal to the first point, 0.1 is very near the first point, 0.5 is half-way in between, etc. The lerp function is convenient for creating motion along a straight path and for drawing dotted lines.
您可以创建一个变量,用作多次调用 draw()
函数之间的 amt
参数。然后随着时间的推移增加该变量来移动该点,并在那里绘制圆圈。
关于java - 加工时如何将圆移过线?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36252964/
例如,如果我想记录我按下了 b 键并想记录按下该键的时间长度,我该怎么做? 最佳答案 处理起来 super 简单。看看keyPressed()和 keyReleased() . // create a
我正在为编程课创建一个突破游戏。 import processing.serial.*; //sets the conditions for winning int lose = 1; boolean
有人可以告诉我为什么我会收到此错误吗?基本上这是一个我想模拟基本植物生长的程序。我想以这样的方式做到这一点:花瓣都存储在一个圆圈数组中。 Stem myStem; Circle circles; fl
我想知道如何更改以下代码,以便将形成花瓣的圆圈存储在数组中。所以我可以在另一个函数中使用它。 void setup() { size(400, 400); smooth(
我编写了这段代码来创建速写本。 我确定这是一个简单的错误,但为什么它不会在图像结束时停止播放? 这是代码 import ddf.minim.spi.*; import ddf.minim.si
我的start-yarn.sh无法启动resourcemanager和nodemanager进程 如前所述,我在yarn-env.sh脚本中设置了这些选项。 export YARN_RESOURCEM
我试图让我的粒子系统一个接一个地生成粒子,而不是同时生成所有粒子。我的代码目前将立即生成所有 100 个粒子。 我没有尝试太多,因为我是编码新手。 我有一个设置,可以调用并更新我的粒子类,以及一个包含
我正在尝试为这个程序制作一个重置按钮,我到处都找过了,但找不到有效的方法。我试图在游戏结束时,当你输了时,你按“重新启动”,游戏将从草图的开头开始。该程序工作正常,但一旦按下“重新启动”按钮,我会在控
我有一个移动图像作为背景 PImage background; int x=0; //global variable background location rocket Rocket; void s
我有一个移动图像作为背景 PImage background; int x=0; //global variable background location boolean up; boolean d
我的 Enemy 变量在 GameScene 函数中不“存在”。我正在尝试制作一个正在处理的游戏,但由于某种原因,当我尝试访问一个类时,我收到错误消息“x 无法解析或不是一个字段”,我将在下面发布我的
我正在创建一个程序,通过采用以下输入来计算一顿饭的总费用:meal_cost,tax_rate,tip_rate,number_eating 并通过函数调用将它们打印在字符串中。我查看了 StackO
首先,本文不涉及表单验证(javascript),而是有关数据库约束的验证。 当我通过添加表单添加数据时,由于我在创建数据库时已初始化的数据库限制(例如复制主键),在某些情况下数据库将不会更新。在这种
我是一名优秀的程序员,十分优秀!