【问题标题】:Getting a line to move along the tangent line of a circle in Processing在处理中让一条线沿着圆的切线移动
【发布时间】:2014-09-15 16:07:08
【问题描述】:

我有一个点沿着圆的路径,在确定的时间,我希望该点“断开”并沿着切线行进。我怎么找到这个?有人告诉我,导数是

x = -sin(时间)

y = -sin(时间)

(不确定我是否理解我被告知的“时间”部分),但我不明白这足以让我的观点沿着这条线传播。有小费吗?这是我目前拥有的。

/*
Rotor draws circle for random period of time, then moves
in a straight direction for a random period of time, beginning a 
new circle
*/

Rotor r;
float timer = 0;
boolean freeze = false;

void setup() {
  size(1000, 600);
  smooth();
  noFill();
  frameRate(60);
  background(255);

  timeLimit();
  r = new Rotor(100, 100, random(40, 100));
}

void draw() {
  timer = timer + frameRate/1000;

  if(timer > timeLimit()) {
    timer = 0;
    timeLimit();

    if(freeze == true) { 
      freeze = false;
    } else {
      freeze = true;
    }
  }

  if(!freeze) {
    r.drawRotor(); 
  } else {
    r.holdSteady();
  }
}

float timeLimit() {
  float timeLimit = random(100); 
  return timeLimit;
}

转子类:

class Rotor {

  color c;
  int thickness;
  float xPoint;
  float yPoint;
  float nXPoint;
  float nYPoint;
  float radius;
  float angle = 0;
  float centerX;
  float centerY;
  float pointSpeed = frameRate/100;

  Rotor(float cX, float cY, float rad) {
    c = color(0);
    thickness = 1;

    stroke(c);
    strokeWeight(thickness);

    centerX = cX;
    centerY = cY;
    radius = rad;
  } 

  void drawRotor() {
    angle = angle + pointSpeed;
    xPoint = centerX + cos(angle) * radius;
    yPoint = centerY + sin(angle) * radius;
    ellipse(xPoint, yPoint, thickness, thickness);
    strokeWeight(2);
    ellipse(centerX, centerY, 5, 5);
  }

  void holdSteady() {
    xPoint = -sin(angle);//need tangent of circle
    yPoint = -cos(angle);
    ellipse(xPoint, yPoint, 4, 4);
    //then set new center x and y
  }

  void drawNewRotor(float cX, float cy, float rad) {

  }

}

【问题讨论】:

    标签: java processing calculus


    【解决方案1】:

    您可以使用tan()

    int f =100;
    size(300,300);
    stroke(0);
    translate(width/2, height/2);
    for(int i = 0; i< 360; i++){
        point(cos(radians(i))*f,sin(radians(i))*f);
        point(f,tan(radians(i))*f);
        point(tan(radians(i))*f,f);
        }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2012-08-15
      • 2014-06-25
      • 2016-08-06
      • 2022-10-14
      • 1970-01-01
      • 1970-01-01
      • 2020-10-12
      • 2013-10-08
      相关资源
      最近更新 更多