We are about to switch to a new forum software. Until then we have removed the registration on this forum.
hi there, I am calculating cosine of 2 high dimensional vectors. like PVector p1 (a1,b1,c1,d1,e1.....n1) PVector p2 (a2, b2, c2,d2,e2.....n2)
the thing is that I got value of a1, b1... from a for loop,
for (int j = 0; j < target1.pixels.length; j++)
{
target1[j] = green(target1.pixels[j]);
target2[j] = green(target2.pixels[j]);
}
so the array of target1 is all the values that I want to put into my PVector. But I don't know how to put those values into my PVector... I was doing like
p1 = new PVector(target1[j]);
p2 = new PVector(target2[j]);
But obviously it dose not work ...( PVector(float) dose not exist )
So dose someone have any idea about it? Not sure my question is clear enough....
Answers
How about:
p1 = new PVector(target1[j], 0);
? ;;)Although I don't get why you'd wanna use a PVector just to store 1 green() color. @-)
@GoToLoop
Actually what I want is p1 = new PVector(target1[1], target1[2], target1[3], ...... target1[n])
a vector has n dimensions..
I think you're mixing the concept of Vector as a container w/ as of x, y & z coordinates.
If you wanna store all your green() values, you can use an array of
color[]
for example.A faster variant w/o green(): :ar!
@GoToLoop
Yes in this case the vector is just a container...
well...what I had is an image of pixels 400 for example (20*20) and each pixels has its green value from 0-255. So in total I have 400 numbers, indicating 400 pixels' green value. and I want these 400 numbers to be put into an PVector.. which has more than 3 dimensions..
Is it achievable?
Cos later on I need to do calculation using dot product of a vector, so I don't think it is wise for me to use colour() as a container..
And thanks soooo much for your quick reply!!! And also merry xmas
Have you read what exactly is Processing's PVector class? 8-|
https://Processing.org/reference/PVector.html
It's a tiny container for 3 values only: x, y & z.
It can't store 400 values in it at all!!! :-@
And those 3 fields are supposed to represent coordinates, not colors! :-\"
@GoToLoop
Oh! my!
cos tutor said that we can regard numbers as a high dimensional vector, so I take it as a PVector.....
Well maybe the simplest way is to put them just as arrays....
Thank you so much!
Glad you've got it now! :-j "dimensional vector" is simply a synonym for an array's index I guess. ;)
BtW, Java got a container class called Vector: :-$
http://docs.Oracle.com/javase/8/docs/api/java/util/Vector.html
However it's deprecated in favor of ArrayList: B-)
https://Processing.org/reference/ArrayList.html
If you think along the domain of RGB or HSB, then PVector could represent color (sorry... not alpha in this formula). Then you can think of a color image in the color domain of three dimensions. To contain 400 colors, you will need an ArrayList.
Why do you want to think this way, representing color in a 3D space? If you take a picture for example, and then you select a shade of green from your picture, you can do operations of this color on your image. For example, you can define a color distance in order to select all colors close to your selected color using linear algebra. Another example, using the dot product of your current color against another color, it will provide a level of overlapping between them.
Kf