Oh I see, drawing it on GIMP will definitely be a herculean task. For that I was thinking of getting graph sheets on the internet. There will be many of them on the net, they are usually in .pdf format and converting them to image file i.e. .jpeg won't be a problem. To derive the angle of a straight line. assuming it is for the line made of circles 3 and 4, the equation to use will be; first you get the gradient, same as slope of the line gradient = -((y3 - y4)/(x3 - x4)); then you take a step further to determine the angle = (atan(gradient))*360/2/PI;
This is definitely the solution to determine the angle of a straight relative to the horizontal(x) axis. I’ve include the link for ease of understanding.
Please let me know If you want the angles in another relative/reference position.
The problem I’m having at the moment I want you to help me solve is: parsing a string of numbers separated by comma’s into an array. The string of numbers will be typed into an input box and then parsed into an array when a button is clicked.
Thanks Chris for the reply, I’ve tried parsing the data but I couldn’t. In addition to the split function, their is also the input function and the button function to deal with that’s why I couldn’t solve the problem. Basically it involves creating a user interface comprised of an input box and a submit button.
Yes, I’m aware of that. Along atan2() you can also use angleBetween(). But you have to translate() to set both start points at 0,0 And then some weird things happened. Tomorrow I will have a look at it again.
@Chrisir I spent some more hours trying to calculate the angle between two lines, but I just can’t get the exact values using the provided translate() angleBetween() or atan2(). I remember doing this in java , but now I ended up using plain geometry calculation getting the acos of the fracture of the dot product of the two vector lines divided by the product of the squared lengths, which works in sketch below But I really would like to use the functions above. Have you done this before in P5.js?
What is what you actually want? Something like the code below?
I prefer text explaining instead of having to watch a video.
I also noticed that you wrote an angle code above. It’s only to the horizontal axis related though,
var my_number_array = [];
var only_numbers = '1234567890.-'
let my_number_string;
let button;
let input;
var sum = 0;
function setup() {
createCanvas(500, 500);
button = createButton('Add to array');
button.position(20, 50);
button.mousePressed(addToArray);
input = createInput('');
input.position(20, 20);
input.input(myInputEvent);
input.elt.focus();
}
function draw() {
background(255);
for (let i = 0; i < my_number_array.length; i++) {
text(my_number_array[i], 250, 35 + (i * 20));
}
text('Sum of numbers in array = ' + sum, 300, 35);
}
function addToArray() {
sum = 0;
if(my_number_string != '') my_number_array.push(my_number_string);
for (let i = 0; i < my_number_array.length; i++) {
sum = sum + float(my_number_array[i]);
}
input.elt.focus();
input.value('');
my_number_string = '';
}
function myInputEvent() {
if ((only_numbers.indexOf(key) == -1)) {
alert("Not a number");
input.value('');
} else {
my_number_string = this.value();
}
}
Thank you very much for your efforts, the reference angle relative to the horizontal axis opens up the use of angles to a lot of possibilities, you have done a great job with that. The string of comma seperated numbers will be added to the array in one instance on the click of a button. They will include negative numbers. Example we have an array ;[“2,3,7,-9,4,-3”] and after the button is clicked it becomes [“2”,“3”,“7”,"-9",“4”,"-3"]. The string split function will be required to perform this operation.
Ok, that’s simple, but where is the outcome going to be used for? I mean it isn’t saveStrings(), is it?
Or do you want the outcome printed in the console?
The comma separated numbers will be typed into an input box, then after the click of a button they are stored as an array. It is a user interactive interface. Thanks for your efforts.
I must say that reading your latest posts, they all request something different, and you never reveal if my latest posts are in some way useful for you, so I will leave it by this.