How do you get the magnitude of a vector?

About advanced scenes, and the Thyme scripting language used in Algodoo.

How do you get the magnitude of a vector?

Postby Death_noob » Sat Jan 28, 2017 10:21 pm

Please help!
Death_noob
 
Posts: 11
Joined: Sat Jan 28, 2017 10:17 pm

Re: How do you get the magnitude of a vector?

Postby Xray » Sun Jan 29, 2017 2:34 am

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)
User avatar
Xray
 
Posts: 500
Joined: Sun Jun 17, 2012 6:12 am
Location: USA

Re: How do you get the magnitude of a vector?

Postby Death_noob » Wed Feb 01, 2017 2:54 am

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?

Postby Xray » Wed Feb 01, 2017 4:34 am

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?
User avatar
Xray
 
Posts: 500
Joined: Sun Jun 17, 2012 6:12 am
Location: USA

Re: How do you get the magnitude of a vector?

Postby Death_noob » Thu Feb 02, 2017 5:43 am

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])
Death_noob
 
Posts: 11
Joined: Sat Jan 28, 2017 10:17 pm

Re: How do you get the magnitude of a vector?

Postby Death_noob » Thu Feb 02, 2017 5:45 am

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?

Postby Xray » Thu Feb 02, 2017 9:01 am

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.
User avatar
Xray
 
Posts: 500
Joined: Sun Jun 17, 2012 6:12 am
Location: USA

Re: How do you get the magnitude of a vector?

Postby Death_noob » Fri Feb 03, 2017 3:18 am

Death_noob
 
Posts: 11
Joined: Sat Jan 28, 2017 10:17 pm

Re: How do you get the magnitude of a vector?

Postby Death_noob » Fri Feb 03, 2017 3:21 am

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?

Postby Xray » Fri Feb 03, 2017 4:39 am

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!
User avatar
Xray
 
Posts: 500
Joined: Sun Jun 17, 2012 6:12 am
Location: USA

Re: How do you get the magnitude of a vector?

Postby Xray » Fri Feb 03, 2017 7:04 am

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....
User avatar
Xray
 
Posts: 500
Joined: Sun Jun 17, 2012 6:12 am
Location: USA

Re: How do you get the magnitude of a vector?

Postby Death_noob » Sat Feb 04, 2017 12:56 am

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.
Death_noob
 
Posts: 11
Joined: Sat Jan 28, 2017 10:17 pm

Re: How do you get the magnitude of a vector?

Postby carl00s01 » Sun Feb 05, 2017 2:20 am

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
User avatar
carl00s01
 
Posts: 24
Joined: Fri Nov 26, 2010 7:03 pm
Location: Brazil

Re: How do you get the magnitude of a vector?

Postby Death_noob » Wed Feb 08, 2017 12:26 am

carl00s01 I am not good at coding at all, but I tried this
Code: Select all
e.this.adhesion = x*math.vec.len(vel)
but it didn't work.
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?

Postby carl00s01 » Wed Feb 08, 2017 2:00 am

Here's a working example. Check the ball's script menu.
Attachments
example.phz
(18.03 KiB) Downloaded 123 times
User avatar
carl00s01
 
Posts: 24
Joined: Fri Nov 26, 2010 7:03 pm
Location: Brazil

Re: How do you get the magnitude of a vector?

Postby Xray » Wed Feb 08, 2017 3:04 am

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!
User avatar
Xray
 
Posts: 500
Joined: Sun Jun 17, 2012 6:12 am
Location: USA

Re: How do you get the magnitude of a vector?

Postby carl00s01 » Wed Feb 08, 2017 5:51 pm

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.
User avatar
carl00s01
 
Posts: 24
Joined: Fri Nov 26, 2010 7:03 pm
Location: Brazil

Re: How do you get the magnitude of a vector?

Postby Death_noob » Fri Feb 10, 2017 3:26 am

thanks :clap:
Death_noob
 
Posts: 11
Joined: Sat Jan 28, 2017 10:17 pm

Re: How do you get the magnitude of a vector?

Postby Luezma » Fri Apr 07, 2017 4:56 am

To get any vector magnitude, use pythagoras theorem [sqrt(x^2 + y^2)] (translated in one simple Thyme line):
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?

Postby FRA32 » Thu Apr 20, 2017 3:50 pm

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


Return to Thyme scripting

Who is online

Users browsing this forum: No registered users and 6 guests