Loading...
Logo
Processing Forum
Hello guys,

I would like to draw vectors with different origins. How this is possible as in  PVector() you can assign only the end of the vector? I used translate() function but changes the origin of all the draw panel. 

Replies(5)

How are you drawing the vectors? If you are using line() you could use the origin for the first three coordinates, no translations needed.
For example I need a vector starting from (0,0) and end to (100,100) and  another from (200,200) to (400,400). Also I need to use the heading() function to calculate the angle of rotation.
A vector is either a point in space or a direction, if you want to visualize a vector usually you draw a line. Visualizing vector (0,0) to (100,100)  and  (200,200) to (400,400) can be done:

line(0,0,100,100);
line(200,200,400,400);

The PVector is just a storage bin to store the x,y,z coordinates of a vector, this you can use for calculating the angle of rotation:

myVector = new PVector(100, 100);
println(myVector.heading());

Should you want the rotation of your (200,200) to (400,400) vector you will first have to substract the two points of your vector to get the direction (400-200, 400-200).

Hope this helps you.

Thanks a lot. I actually have a thought to connect cloud points with vectors in pairs in order to understand if there are a part of a plane by calculate there heading, i.e if the angle is close to 0, is a plane. I did some test but with no luck till now....
I dont know exatly what you mean but what i do know is that there is
1 always a plane through three given points
2 always a plane through one point and one vector

Getting that plane using angle between is not the easiest method i think. There are a lot of math websites that show you ways to calculate.

If you mean to find out if two lines are in the same plane you have to check 2 things:
are the lines (vectors) paralel (just normalize them and check if the normalised vectors are the same or inverse)
do the lines intersect, http://processingjs.org/learning/custom/intersect/  a processing script containing that code

if one of these conditions is met then the vectors are in the same plane