View Full Version : How to find crossing coordinates?
geebee
November 16th, 2005, 09:35 AM
Greetings everyone,
My question is based of this .gif I'm attaching.
On this sketch, if the green part is the ground - lets say groundMC and the orange pole is poleMC (the blue dot being the center of rotation (pivot point) of poleMC).
What would a piece of code inside an poleMC.onEnterFrame function look like if it was to capture the x coordinate of the point where poleMC touches groundMC (where the red arrow is pointing at)?
You could also say that I'm trying to figure out how to tell flash the x coordinate of the exact point where the shape of poleMC enters the shape of groundMC. The collision points of all those parts of poleMC that is below the surface of groundMC doesn't matter to me i this example - its only the "entry point" (if you can call it that) I'm looking for here..
Hope the above makes sense to you gurus...
Any suggestions to code solutions or thoughts on best approach would be very welcome.
-GB
Dauntless
November 16th, 2005, 12:57 PM
So the position of the blue dot is given and the angle of the orange bar?
GPP
November 16th, 2005, 10:28 PM
Wait wait.. this?
//Trace poles x cods
trace(_root.pole._x)
mistoflight
November 17th, 2005, 12:11 AM
Greetings everyone,
My question is based of this .gif I'm attaching.
On this sketch, if the green part is the ground - lets say groundMC and the orange pole is poleMC (the blue dot being the center of rotation (pivot point) of poleMC).
What would a piece of code inside an poleMC.onEnterFrame function look like if it was to capture the x coordinate of the point where poleMC touches groundMC (where the red arrow is pointing at)?
You could also say that I'm trying to figure out how to tell flash the x coordinate of the exact point where the shape of poleMC enters the shape of groundMC. The collision points of all those parts of poleMC that is below the surface of groundMC doesn't matter to me i this example - its only the "entry point" (if you can call it that) I'm looking for here..
Hope the above makes sense to you gurus...
Any suggestions to code solutions or thoughts on best approach would be very welcome.
-GB
I think I understand what you are trying to say be here goes. Basically, you have a blue dot which has a pole rotating around. I pretty sure you also would be using a rotation angle of theta with polar coordinates as this would be the easiest so I order to find out the x coordinate off where the pole hits the ground you need to first make a collision detections.
//theta = angle of rotation
//radius = lenght of pole
var disY:Number = _root.bluedot._y+(_root.bluedot._height/2)+radius*Math.sin(theta); //Vertical Distance of Pole Extending from Blue Dot
if(disY>_root.ground._y){
var disX:Number = _root.bluedot._x+(_root.bluedot._width/2)+radius*Math.cos(theta); //Horizontal Distance of Pole Extending From Blue Dot
trace(disX);
}
This is ofcouse is assuming that the bluedot's registry point is the top left and the pole rotates around the center of the bluedot. Let me know if that works out for you or not.
geebee
November 18th, 2005, 03:50 AM
Thanks for the replys.
The blue dot doesn't have to be a visible object or even exist. I only placed it in the sketch to indicate the pivot point of the orange pole (the blue dot is only a graphic presentation of the rotation point of the orange pole).
Imagine that the user could rotate the orange pole using fx. the left and right arrow keys. Then the whole idea is to find a way to detect in what x coordinate the "surface" of the green "ground" box is penetrated by the pole.
In fact the width of things is not important - the pole could just be a line and the pole is the object of interest here - not the blue dot. I only placed the blue dot in my sketch because that I figured the point of rotation would be crucial to any math needed to make this work.
I think my first sketch may have confused some of you, so I've done another - hopefully this one will do a better job of showing you what I'm after. The x coordinates in this new sketch are entirely fictional and only meant to illustrate what i'm after:
If my .swf was running at 20 fps and the orange pole (or line if you prefer) can be rotated by the player using arrow keys then in each frame I want to be able to trace the exact x coordinate where the orange pole/line impacts/penetrates/hits the top line/surface of the green "ground".
In the new sketch I've drawn what could be to frames of the desired effect.
I'm hoping the clears things up a bit - I really don't know a better way to explain myself than this :)
As always I'm looking forward to your replys
-GB
ElectricGrandpa
November 18th, 2005, 10:39 AM
First you need the slope and y-intercept of both lines... y = mx+b
y = m1x+b1 : the ground equation
y = m2x+b2 : the line equation
solve for x
m1x+b1= m2x+b2
so... iX = (b2-b1)/(m1-m2)
That's the x equation of the intersection point between the two lines... We can also get the y from that...
iY = m1(iX)+b1
Then just measure the distance between the rotation point and the intersection point... Make sure it's less than the length of the rod.
sqrt((iX-rX)(iX-rX) + (iY-rY)(iY-rY)) has to be less than rod.length... if it is, then we know that iX,iY is the place where the rod hits the ground.
I'll probably make an example later today if I have time... Let me know if anything is really confusing or unclear or wrong... :)
-Matt
Powered by vBulletin® Version 4.1.10 Copyright © 2012 vBulletin Solutions, Inc. All rights reserved.