Linear Distance?

For questions about using Classic.

Post » Sun Jul 31, 2011 8:08 am

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


B
51
S
10
G
7
Posts: 184
Reputation: 6,825

Post » Sun Jul 31, 2011 11:30 am

Unless I misunderstood, it simply is

distance(red.X, red.Y, green.X, green.Y)
Image
B
23
S
8
G
10
Posts: 1,820
Reputation: 8,242

Post » Sun Jul 31, 2011 11:35 am

Tulamide, I thinks he wants to know how to get the Y coordinate for any point on the line between green and red.Kyatric2011-07-31 11:36:37
New to Construct ? Where to start

Image Image
Image Image

Please attach a capx to any help request or bug report !
Moderator
B
247
S
85
G
40
Posts: 7,000
Reputation: 57,805

Post » Sun Jul 31, 2011 12:53 pm

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
tulamide2011-07-31 12:54:49
Image
B
23
S
8
G
10
Posts: 1,820
Reputation: 8,242

Post » Sun Jul 31, 2011 1:08 pm

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 ?
New to Construct ? Where to start

Image Image
Image Image

Please attach a capx to any help request or bug report !
Moderator
B
247
S
85
G
40
Posts: 7,000
Reputation: 57,805

Post » Sun Jul 31, 2011 1:15 pm

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.tulamide2011-07-31 13:17:27
Image
B
23
S
8
G
10
Posts: 1,820
Reputation: 8,242

Post » Sun Jul 31, 2011 9:30 pm

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





B
51
S
10
G
7
Posts: 184
Reputation: 6,825

Post » Sun Jul 31, 2011 9:49 pm

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)
Spriter Dev
B
88
S
21
G
12
Posts: 3,240
Reputation: 16,486

Post » Sun Aug 07, 2011 5:54 am

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
B
51
S
10
G
7
Posts: 184
Reputation: 6,825


Return to Help & Support using Construct Classic

Who is online

Users browsing this forum: No registered users and 1 guest