GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — PVector.angleBetween() returns 0 for 3D vectors whenever x and y are both 0 · Issue #2045 · processing/processing

PVector.angleBetween() returns 0 for 3D vectors whenever x and y are both 0 #2045

New issue
Copy link
New issue
Copy link
Closed
Closed
PVector.angleBetween() returns 0 for 3D vectors whenever x and y are both 0#2045
Copy link
Assignees
shiffman

Description

@sebhunt
sebhunt
opened on Aug 27, 2013
Issue body actions

PVector.angleBetween(PVector, PVector) returns 0 for 3D vectors whenever the x and y components of a parameter are both 0. For example:

PVector.angleBetween(new PVector(0,0,1), new PVector(1,0,0))

returns 0 instead of PI/2.

Looking at the source code, it seems clear what is wrong:

// We get NaN if we pass in a zero vector which can cause problems
// Zero seems like a reasonable angle between a (0,0) vector and something else
if (v1.x == 0 && v1.y == 0) return 0.0f;
if (v2.x == 0 && v2.y == 0) return 0.0f;

Activity

  1. shiffman commented on Aug 27, 2013

    @shiffman
    shiffman
    on Aug 27, 2013
    Member
    More actions

    Thank you for the post.

    Certain methods, like heading() and angleBetween() are only relevant for 2D. In 3D, for example, we have to ask the question "heading along what axis?", "angle between relative to what axis?" I think I should make some updates to the reference to make this more clear. If you are looking for more sophisticated 3D math with vectors, check out toxiclibs geom package.

    (Also, I think you meant PVector.angleBetween(new PVector(0,0,1), new PVector(0,0,0)) FYI).

  2. shiffman
    closed this as completedon Aug 27, 2013
  3. sebhunt commented on Aug 27, 2013

    @sebhunt
    sebhunt
    on Aug 27, 2013
    Author
    More actions

    (Not sure if commenting on closed issues is frowned upon but..). Ok, I guess, if that's the intention. But the PVector source code that I was looking at (0219-2.0.1) looks very much like it was written with 3D vectors in mind; it uses dot-product and interprets "angle between" as meaning the angle in the plane defined by the given pair of vectors, which I think is pretty standard). And I think the code would work too, if only those first two lines that I quoted were amended to:

    if (v1.x == 0 && v1.y == 0 && v1.z == 0) return 0.0f;
    if (v2.x == 0 && v2.y == 0 && v2.z == 0) return 0.0f;
    

    (And I really did mean PVector.angleBetween(new PVector(0,0,1), new PVector(1,0,0)).)

  4. shiffman commented on Aug 27, 2013

    @shiffman
    shiffman
    on Aug 27, 2013
    Member
    More actions

    Ahhhhhhh, sorry, I read your post too quickly and had a knee-jerk 2D only reaction. I see what you are saying now. Let me go back and look at this more.

  5. shiffman
    reopened this on Aug 27, 2013
  6. ghost assigned
    shiffman
    on Aug 27, 2013
  7. shiffman commented on Aug 29, 2013

    @shiffman
    shiffman
    on Aug 29, 2013
    Member
    More actions

    Ok, this is now closed via c84a5a5

  8. shiffman
    closed this as completedon Aug 29, 2013
  9. Manindra29
    added a commit that references this issue on Oct 30, 2013

    Update PVector.java

    c84a5a5
  10. davidfokkema
    added a commit that references this issue on Mar 23, 2014

    Update PVector.java

    682305b
  11. github-actions commented on Jun 17, 2021

    @github-actions
    github-actionsBot
    on Jun 17, 2021
    More actions

    This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

  12. github-actions
    locked as resolved and limited conversation to collaborators on Jun 17, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

  • @shiffman
    shiffman

Labels

No labels
No labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

    You are visitor 01402503 — GeezerVison does not store the pages you look up.
    Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.