Alice Community Practicing with using the different types of distances
 User Name Remember Me? Password

 Thread Tools Display Modes
 Practicing with using the different types of distances
 roofy Guest   Status: Posts: n/a Practicing with using the different types of distances - 10-25-2006, 04:30 PM Hi there, In Tues class, we learned how to do a poor man's way of collision detection using some object's distance above another object function. So playing around with the different types there are, in respects of distance to..., I created a scene where the Control Tower object was positioned at 5, 15, 50. I then added a Helicopter object, and placed the helicopter at -5, 15, 50. After setting this scene up, I created some code that said this... scalarx = absolute value -> round -> Helicopter distance to the right of ControlTower. print scalarx as a string then I ran the program, and thinking the distance should be 10.0, it was not so. Instead it was 18.0. So then I moved the helicopter to the same position as the ControlTower, thinking now the code should print out as 0.0, but I still got an amount of 8.0. So my question is why is there still a distance of 8 even though the Helicopter and Control Tower are both in the same location?
 The "center" of an object is not always at the obvious place.
 DrJim Guest   Status: Posts: n/a The "center" of an object is not always at the obvious place. - 10-25-2006, 08:37 PM Think the title says it all - don't have Alice running right now but I think the control tower is one of the objects where the "center" is not in the obvious place. You can always find the center just by looking at where the axis start in the bounding box - just need to be sure you're really looking at the object you think you are. (For some nice pictures of this, see Dunn, et al, pp. 44-46). There is no way within Alice that the center can be changed - thus when you get scaling problems, etc. with the existing local coordinate systems - you're basically stuck. (You can fix a few problems by adding invisable objects and using them as pivot points by making them vehicles for other parts - but that gets really messy if you have to do it a lot.)
 roofy Guest   Status: Posts: n/a 10-25-2006, 09:30 PM well then is there any possible way of getting what position x is according to where the object is current located at? And why can I not subtract a vector with another vector, or multiply a vector with a scalar? and do not tell me the reason is because Alice is just a learning tool. In my opinion, vectors and scalars are the most important part of learning to program in 3d space.
 roofy Guest   Status: Posts: n/a 10-25-2006, 09:48 PM my point I am getting at is if there is a way to find what x, y, z are then you can use the Pythagorean Theorem where the formula is this... sqrt((x_2 - x_1)^2 + (y_2 - y_1)^2 + (z_2 - z_1)^2)) but when I drag the object position tile, it does not give me the choice of choosing x, y, or z. Instead I get an error.
 DrJim Guest   Status: Posts: n/a 10-26-2006, 12:07 AM Take a look at http://www.alice.org/community/showthread.php?t=425 for a start - a rather convoluted way to move something to specific absolute (world) or local (object) coordinates. Also you can get the position and/or orientation of any object by looking at the point of view of the object in it's properties list or read it out by the appropriate function - I've honestly only used that when the vehicle is the world and thus the coordinates are world-level references. Really don't see how this applies to what (I thought ) was your first question - if the person who modeled the object put the local origin at an inconvenient place for you - you'd still be stuck with a lot of calculactions even if the data was more convenient to access.
roofy
Guest

Status:
Posts: n/a
10-26-2006, 03:43 PM

Quote:
 Originally Posted by DrJim Take a look at http://www.alice.org/community/showthread.php?t=425 for a start - a rather convoluted way to move something to specific absolute (world) or local (object) coordinates.
I took a look at your directed link and I could not understand it too much with what you were saying and your picture was too small to see your code.

Quote:
 Originally Posted by DrJim I've honestly only used that when the vehicle is the world and thus the coordinates are world-level references...
that is a good point, and I did not think of that. Though, for what I am doing for my project it would do because the vehicle of all of my objects are in world space. However, there is a way in real math, you can find the world space coordinate position of an object by multiplying the transform by a local space postion or it is something close to that manner, but I do not think you can do this in Alice.

Quote:
 Originally Posted by DrJim Really don't see how this applies to what (I thought ) was your first question....
well to clarify that it somewhat does, it is because my first theory was since

(X_2 - X_1)
...is the samething in an Alice function as objectA distance to the right of objectB ...and

(Y_2 - Y_1)
... is the samething in an Alice function as objectA distance above objectB ...and

(Z_2 - Z_1) is the samething in an Alice function as objectA distance in front of objectB

... so therefore what I was thinking at first was why couldn't I do this...
assume that objectA is helicoptor, and objectB is the ControlTower

Code:
```distanceX set the value to  (objectB distance to the right of objectA) of 2nd power
distanceY set the value to (objectB distance above objectA) of 2nd power
distanceZ set the value to (objectB distance in front of objectA) of 2nd power
totalDistance set the value to (sqrt of (distanceX + distanceY + distanceZ)```
... but the problem was that I was not getting accurate results. So in theory it is the same but I just did not state about the Pythagorean Theorem in my original question because I did not think it was necessary at the time.

All in all, I did come up with a work around which I have attached the a2w file below if anyone is interested in it.

How I came up with this solution was at first when I draged a position tile onto an index variable, I was getting an error stating that the drop failed. So then I got a little clever by trying to see if I made the object tile as a position variable first; then see if I could drag that variable onto an index variable which I could. So I stayed with that theroy and applied the Pythagorean Theorem formula aftwards, and I get the exact distances that I want.

here is the file if anyone is interested
Attached Files
 found solution to get the true distance of 2 objects.a2w (708.0 KB, 408 views)

 Slight correction.
 DrJim Guest   Status: Posts: n/a Slight correction. - 10-27-2006, 12:04 PM The code does show the solution nicely - but you left out the squares and square roots in the version you posted. Since they were in your equations, this was probably either an oversight or an early version of the code. I'm also glad to see you taking the time to really work through this, rather than just believing the first thing you see come up on the screen. I still don't really understand your original question/comments but - if you do, that's fine. One nice thing about an interactive program like Alice is that sometimes you can get the answer you need quicker than really nailing down the exact specifics of the question. However, when I use your (corrected) code - I still always get the same answer as a simple "distance from --- to ---" call. Is there some case you don't see this happening? Don't think I really helped you much, if any, here - but I'm always glad to try.
roofy
Guest

Status:
Posts: n/a
10-27-2006, 06:14 PM

Quote:
 Originally Posted by DrJim The code does show the solution nicely - but you left out the squares and square roots in the version you posted. Since they were in your equations, this was probably either an oversight or an early version of the code.
Firstly, the reason why I did not use the same code is because if you look at the function called getDistanceOf[a], I used the world function "absolute value of" instead. Let me explain this a little better

let say that object a (x) value is 10 and object b value is 5.
So the solution is objectB - objectA which is

5 - 10 = -5

the problem with that is distance values are always positive but the example above the answer is negative.

So if we square it and then sqare root it the negative distance will be positive like so..

-5^2 = +25
sqrt(25) = +5

so if the above is true, isn't the absolute value of (-5) +5? The answer is yes

so in other words I did it with the absolute method instead, because it is less lines of code.

Quote:
 Originally Posted by DrJim However, when I use your (corrected) code - I still always get the same answer as a simple "distance from --- to ---" call. Is there some case you don't see this happening?
Yes and no. No I should not of reproduced another 3 axis distance. Yes I do see a difference when you want the distance of 2 axis points or just one axis point. The problem with that is if you use "distance to the right of" or "distance above" etc, like you said if the pivot point is not in the center of the object, then you can weird reults as an answer. However, with my function, it will always be acurrate because it uses the location of where the pivot is located at in space. So in other words the pivot point can be anywhere in space and it does not always have to be in the center.

I hope that clears things up for you, and I appreciate you chippin in.

 Thread Tools Display Modes Linear Mode

 Posting Rules You may not post new threads You may not post replies You may not post attachments You may not edit your posts BB code is On Smilies are On [IMG] code is On HTML code is Off Forum Rules
 Forum Jump User Control Panel Private Messages Subscriptions Who's Online Search Forums Forums Home Announcements     Community News and Announcements Alice 3     How Do I?     Works In Progress     Share Your World     Share Custom Classes     Bugs and Trouble Shooting     Suggestion Box Alice 2     How do I...?     Works-In-Progress     Share Worlds     Share Objects     Bugs and Troubleshooting     Suggestion Box Educators     Teaching with Alice     Teaching Using Alice 3     Teaching Using Alice 2     CS Principles and Alice     AP CSA and Intro to Java and Alice     Workshops General Discussion     Questions and Comments     The Lounge