How do you get the magnitude of a vector?
20 posts • Page 1 of 1
How do you get the magnitude of a vector?
Please help!
- Death_noob
- Posts: 11
- Joined: Sat Jan 28, 2017 10:17 pm
Re: How do you get the magnitude of a vector?
I'm not sure if this is what you want, but this will give you the distance (magnitude) of a vector between two geometry positions: math.vec.dist(geom1POS,geom2POS)
-
Xray - Posts: 500
- Joined: Sun Jun 17, 2012 6:12 am
- Location: USA
Re: How do you get the magnitude of a vector?
Thanks, but I am using it to get the speed of an object and it doesn't work
- Death_noob
- Posts: 11
- Joined: Sat Jan 28, 2017 10:17 pm
Re: How do you get the magnitude of a vector?
You can get the speed of any object by its "vel" property. Vel returns X and Y velocities. Can't you use that?
By the way, what is "it" in your recent post?
By the way, what is "it" in your recent post?
-
Xray - Posts: 500
- Joined: Sun Jun 17, 2012 6:12 am
- Location: USA
Re: How do you get the magnitude of a vector?
I want to get the total not just one or the other and adding them would not work for diagonals or negative directions.
"it" was using math.vec.dist(e.this.vel , [0,0])
"it" was using math.vec.dist(e.this.vel , [0,0])
- Death_noob
- Posts: 11
- Joined: Sat Jan 28, 2017 10:17 pm
Re: How do you get the magnitude of a vector?
I'm not very advanced when it comes to scripting.
- Death_noob
- Posts: 11
- Joined: Sat Jan 28, 2017 10:17 pm
Re: How do you get the magnitude of a vector?
Well, there's your problem! You are asking the function to return the distance between a velocity and a position, which of course is invalid.
You got me a little confused because in your original post you asked for the "magnitude of a vector", and then in a subsequent post you asked for a velocity. Are you sure that you know exactly what you need? I think in this situation it might be better if you could post a sample scene which describes in detail what you are trying to accomplish. Once I see your scene, there's a much better chance that I'll be able to figure out your problem. Could you do that? You could either post the scene here in the forum, or you can post it on Algobox. Either way is okay with me.
You got me a little confused because in your original post you asked for the "magnitude of a vector", and then in a subsequent post you asked for a velocity. Are you sure that you know exactly what you need? I think in this situation it might be better if you could post a sample scene which describes in detail what you are trying to accomplish. Once I see your scene, there's a much better chance that I'll be able to figure out your problem. Could you do that? You could either post the scene here in the forum, or you can post it on Algobox. Either way is okay with me.
-
Xray - Posts: 500
- Joined: Sun Jun 17, 2012 6:12 am
- Location: USA
Re: How do you get the magnitude of a vector?
I thought [0,0] was a vector, and e.this.speed is a vector so i thought it would work.
- Death_noob
- Posts: 11
- Joined: Sat Jan 28, 2017 10:17 pm
Re: How do you get the magnitude of a vector?
Okay, I loaded your scene, and now I need to understand exactly what you want it to do. In your scene description you say: "I want to have it stick to the top bit as it goes up and down and not fly off." Um, I'm not sure what a "top bit" is, and so allow me to reword that statement so that I make sure I understand it. I think you are saying you want the tiny circle, which is controlled by the user, to stay stuck to that very large circle after it jumps off and comes back down. Is that correct? It does do that already, but I noticed that I had to move the tiny circle very slowly and carefully.
Making two objects stick to each other is fairly easy to do.
I have another question for you... In your original post, you wanted to get the magnitude of a vector. Please explain in detail how that would relate to your scene. What vector do you want to know about and why?
I'm getting close to figuring this out for you but before I can give you what you want, I need to fully understand exactly what I am supposed to be looking for!
Making two objects stick to each other is fairly easy to do.
I have another question for you... In your original post, you wanted to get the magnitude of a vector. Please explain in detail how that would relate to your scene. What vector do you want to know about and why?
I'm getting close to figuring this out for you but before I can give you what you want, I need to fully understand exactly what I am supposed to be looking for!
-
Xray - Posts: 500
- Joined: Sun Jun 17, 2012 6:12 am
- Location: USA
Re: How do you get the magnitude of a vector?
Take a look at my comment that I wrote in your scene posted on Algobox. It explains a possible fix for you. Let me know if that will work....
-
Xray - Posts: 500
- Joined: Sun Jun 17, 2012 6:12 am
- Location: USA
Re: How do you get the magnitude of a vector?
Sorry about not being clear, I want the small circle to have an adhesion value proportional to its speed whether its going up, down, left or right so it sticks to objects while moving but can still jump.
Hope that is clear.
Hope that is clear.
- Death_noob
- Posts: 11
- Joined: Sat Jan 28, 2017 10:17 pm
Re: How do you get the magnitude of a vector?
Death_noob wrote:Sorry about not being clear, I want the small circle to have an adhesion value proportional to its speed whether its going up, down, left or right so it sticks to objects while moving but can still jump.
Hope that is clear.
You have to add on update = (e)=>{} something like
- Code: Select all
c := 1;
adhesion = c*math.vec.len(vel)
where c is your constant of proportionality
-
carl00s01 - Posts: 24
- Joined: Fri Nov 26, 2010 7:03 pm
- Location: Brazil
Re: How do you get the magnitude of a vector?
carl00s01 I am not good at coding at all, but I tried this
I also tried modifying that code and nothing worked. (Sorry if I am an idiot.)
- Code: Select all
e.this.adhesion = x*math.vec.len(vel)
I also tried modifying that code and nothing worked. (Sorry if I am an idiot.)
- Death_noob
- Posts: 11
- Joined: Sat Jan 28, 2017 10:17 pm
Re: How do you get the magnitude of a vector?
Here's a working example. Check the ball's script menu.
- Attachments
-
- example.phz
- (18.03 KiB) Downloaded 123 times
-
carl00s01 - Posts: 24
- Joined: Fri Nov 26, 2010 7:03 pm
- Location: Brazil
Re: How do you get the magnitude of a vector?
carl00s01 -- Your scene is not the same as Death_noob's. In his scene, the small circle starts out moving in the x direction and then it suddenly accelerates in the y direction when it curves up onto that large circle. The problem is, even with an adhesion value of +inf, the small circle still flies up off the "sticky" surface of the large circle! I found it very challenging to get the small circle to stick very strongly to the large circle without flying off to the sky!
-
Xray - Posts: 500
- Joined: Sun Jun 17, 2012 6:12 am
- Location: USA
Re: How do you get the magnitude of a vector?
Yep, that's right ,Xray, I also saw that problem while playing with his scene. In my scene I was just showing how adhesion is scripted, not that It'd work for his purpose. I'm still thinking a proper way of sticking the ball to the surface, that allow jumping.
-
carl00s01 - Posts: 24
- Joined: Fri Nov 26, 2010 7:03 pm
- Location: Brazil
Re: How do you get the magnitude of a vector?
To get any vector magnitude, use pythagoras theorem [sqrt(x^2 + y^2)] (translated in one simple Thyme line):
To make a small object stick properly, make it stop (in the other object's perspective, in other words, make it go to the collision point's speed)
I hope this help you
- Code: Select all
(x^2 + y^2)^0.5
To make a small object stick properly, make it stop (in the other object's perspective, in other words, make it go to the collision point's speed)
I hope this help you
- Luezma
- Posts: 14
- Joined: Thu Dec 13, 2012 7:19 pm
- Location: Argentina
Re: How do you get the magnitude of a vector?
Or simply use math.vec.len(vector here) to get it using algodoo integrated functions.
- FRA32
- Posts: 229
- Joined: Wed Dec 03, 2014 9:51 pm
20 posts • Page 1 of 1
Who is online
Users browsing this forum: No registered users and 6 guests