Find direction vector is in

I currently have 2 vectors:

PVector a = new PVector ( 100, 100 );
PVector b = new PVector ( 500, 500 );

I need to set a’s heading so that it lines up with b. I’ve been struggling with this for a few days: I tried using atan2 () but it kept giving me a 45 degree angle for some reason. Any ideas?

Hello,

They are both heading in the same direction.

Take a look here for some resources:

It helps to draw vectors when working with them:

void setup() 
  {
  size(300, 300);
  background(255);
  PVector a = new PVector (50, 50);
  PVector b = new PVector (250, 250);
  stroke(255, 0, 0);
  strokeWeight(5);
  line(0, 0, a.x, a.y);
  stroke(0, 255, 0);
  strokeWeight(2);
  line(0, 0, b.x, b.y);
  }

image

:)

1 Like

Yeah after 2 hours of scouring the old forums and Processing documentation I created this post, and I kid you not literally 5 minutes later on youtube the exact tutorial on steering by Daniel Shiffman popped up lol.

1 Like