0 Favourites

Linear Distance?

This forum is currently in read-only mode.
  • I'm not sure if I'm even using the right term for this (Probably not), but I wanted to know if it was possible to do this.

    With knowledge of the height at the Beginning(green) and End(red) points, the angle of the object, and that there will be a linear change in height across the object (As signified by the gradient). Could you calculate the height at any point on this object? If so, how

    <img src="http://dl.dropbox.com/u/10316081/Construct/picture1.png" border="0" />

  • Unless I misunderstood, it simply is

    distance(red.X, red.Y, green.X, green.Y)

  • Tulamide, I thinks he wants to know how to get the Y coordinate for any point on the line between green and red.

  • In general, any y can be calculated from the distance between the anchor point to the new point and the angle between them.

    If in the example image above red is the anchor point and green the one to be calculated, then

    green.y = sin(anglebetweenredandgreen) * distancebetweenredandgreen

    If we talk about a rotated sprite whose width is shrinking and whose pivot point is red, then

    green.y = sin(sprite.angle) * sprite.width

  • How are you supposed to calculate the distance between red and green if you don't know green.y ? ^^

    It seems to me the formula is inadequate for the purpose, isn't it ?

  • Construct 3

    Buy Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Buy Now Construct 3 users don't see these ads
  • Just look again at my example. In the case of a sprite, you always know the distance, it simply is the width of the sprite. You often know the distance without knowing the coordinate ;)

    With a more concrete example to the issue, I could give a more concrete answer.

  • I'm sorry, I probably should have clarified a bit more. First of all, this is for a 3D project that uses overhead maps for collisions. The height I'm referring is Y, but it's 3D Y. What I'm trying to figure out how to do is find the 3DY of any point on a ramp where one end is higher than the other, knowing the XYZ of both points and the angle between them. Obviously if you ran perpendicular to ramp you wouldn't be any higher or lower.

    I did figure out some of it last night. What I was first asking is this: if I had a wall facing at an angle, knew a point it intersected, and knew my location, how could I tell how far I was from it?

    (Cos(Wall.Angle)*(Player.X-Wall.X))+(Sin(Wall.Angle)*(Player.Y-Wall.Y))

    Same basic thing

    Thanks for your help

  • If you know your location, and the intersection point it would just be the distance forumla again distance(intersection.x,intersection.y,you.x,you.y)

    If what you're saying is that you want a height value for any arbitrary point on the line. You could use lerp, and the gett function of the math plugin so it'd be

    Lerp(minheight,maxheight,math.gett(green.x,red.x,arbitrarypoint.x))

    If greenx and redx are equal, you'd use y values.

    If you're one of those plugin shy people, the formula for math.gett is just

    Gett(a,b,x)

    Answer=(x-a)/(b-a)

  • Thanks for the help, I got it working. Here's what I ended up using.

    Lerp(Stairs('StartH'), Stairs('EndH') ,(((Cos(Stairs.Angle)*(Camera.X-Stairs.X))+(Sin(Stairs.Angle)*(Camera.Y-Stairs.Y)))/Stairs.Width))

    Really similar to what Lucid posted except it used the wall distance formula I posted above (Meaning the stairs can be any angle), and didn't have to use gett because of that. And an exe showing what I was aiming for

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)