Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implementation of PVector.setHeading() #193

Closed
arijit4 opened this issue May 1, 2021 · 5 comments
Closed

Implementation of PVector.setHeading() #193

arijit4 opened this issue May 1, 2021 · 5 comments

Comments

@arijit4
Copy link

arijit4 commented May 1, 2021

There's an method named PVector.setHeading() in p5.Vector class of p5.js to set the direction of an vector to any given angle. But there's no such option in Processing. It can be settled down easily. But the function seems more self explanatory and easy to understand. It also goes well with the PVector.heading() method already present in Processing.

An implementation might look like the following :

void setHeading(float angle) {
    this.rotate(angle - this.heading());
}
@benfry
Copy link
Owner

benfry commented Jun 14, 2021

Adding it for parity with p5.js… Here's the full implementation from there:

_main.default.Vector.prototype.setHeading = function setHeading(a) {
  var m = this.mag();
  this.x = m * Math.cos(a);
  this.y = m * Math.sin(a);
  return this;
};

@arijit4
Copy link
Author

arijit4 commented Jun 18, 2021

@benfry In 673a19e, you added

public PVector setHeading(float angle) { 
    float m = mag();
    x = m * Math.cos(a);
    y = m * Math.sin(a);
    return this;
 }

shouldn't it be the following?

public PVector setHeading(float angle) { 
    float m = mag();
    x = m * Math.cos(angle);
    y = m * Math.sin(angle);
    return this;
 }

@benfry
Copy link
Owner

benfry commented Jun 18, 2021

Yes, and it was immediately fixed in the next commit.

@arijit4
Copy link
Author

arijit4 commented Jun 18, 2021

@benfry PVector.setHeding() isn't highlighted as other methods in PVector. But it works perfectly though...

@github-actions
Copy link

This issue has been automatically locked. To avoid confusion with reports that have already been resolved, closed issues are automatically locked 30 days after the last comment. Please open a new issue for related bugs.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Jul 19, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants