Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
1

How do I draw a right triangle when I only have the hypotenuse?

Asked by
Perci1 4988 Trusted Moderation Voter Community Moderator
7 years ago
Edited 7 years ago

First off, I'm doing this on roblox, so remember that I'm dealing with three axes. But it is a triangle, not a pyramid. I'm using raycasting.

Hypothetical triangle

I have the hypotenuse (AB) already drawn, so I know how long it is and everything. I also have the position at the start and the end of this hypotenuse (in 3D roblox space). I have the direction that AC needs to travel. I just don't have the length of it.

That's what I'm trying to find. There's not really any code to show, because it's all correct. My methods are just wrong, and I can't figure it out. Hopefully this is possible. Explain it in layman's terms, please.

1
I'd like to be high on potenuse. User#6546 35 — 7y

1 answer

Log in to vote
1
Answered by
BlueTaslem 18071 Moderation Voter Administrator Community Moderator Super Administrator
7 years ago

If I understand your question correctly, what you're asking for is called vector projection.

Given a vector v and a direction d, find the vector y that points in the direction d but is the "same amount in that direction as v"

Formally, y = x * d + p where x is a real (the distance AC), and p(C-->B) is perpendicular to d (A-->C)

You can take the dot product with respect to the unit vector d to yield the equatoin

y . d = x * d.d + p.d. Since d is unit and d is perpendicular to p, this simplifies to x = y . d.

Thus the distance is given by, in Lua,

local distanceInDirection = vector:Dot(direction)

-- e.g.,

local A = Vector3.new(10, 50, 30)
local B = Vector3.new(18, 36, 7)
local direction = Vector3.new(-1, -1, 0).unit

local vector = B - A
local x = vector:Dot(direction)

local C = A + x * direction
0
It works, so thanks, I just don't understand how vector:Dot(direction) gives you the "projection". Because  dot product is just a1*b1 + a2*b2 + a3*b3 Perci1 4988 — 7y
0
It... just does. An equivalent definition is a:Dot(b) is a.magnitude * b.magnitude * math.cos(theta) where theta is the angle between them. BlueTaslem 18071 — 7y
0
(It's 1 when same direction, and shrinks to 0 as you rotate towards 90 degrees away) BlueTaslem 18071 — 7y
Ad

Answer this question