Skip to content

Implementation of PVector.setHeading() #193

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

Closed
processing-bot opened this issue May 1, 2021 · 5 comments
Closed

Implementation of PVector.setHeading() #193

processing-bot opened this issue May 1, 2021 · 5 comments

Comments

@processing-bot
Copy link
Collaborator

Created by: arijit4

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());
}
@processing-bot
Copy link
Collaborator Author

Created by: benfry

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;
};

@processing-bot
Copy link
Collaborator Author

Created by: arijit4

@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;
 }

@processing-bot
Copy link
Collaborator Author

Created by: benfry

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

@processing-bot
Copy link
Collaborator Author

Created by: arijit4

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

@processing-bot
Copy link
Collaborator Author

Created by: github-actions[bot]

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 Sep 18, 2024
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

1 participant