Advertisement
oopsrainbow4

3D Triangle

Aug 15th, 2022
108
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.19 KB | None | 0 0
  1. local wedge = Instance.new("WedgePart");
  2. wedge.Anchored = true;
  3. wedge.TopSurface = Enum.SurfaceType.Smooth;
  4. wedge.BottomSurface = Enum.SurfaceType.Smooth;
  5.  
  6. local function draw3dTriangle(a, b, c)
  7.     local ab, ac, bc = b - a, c - a, c - b;
  8.     local abd, acd, bcd = ab:Dot(ab), ac:Dot(ac), bc:Dot(bc);
  9.  
  10.     if (abd > acd and abd > bcd) then
  11.         c, a = a, c;
  12.     elseif (acd > bcd and acd > abd) then
  13.         a, b = b, a;
  14.     end
  15.  
  16.     ab, ac, bc = b - a, c - a, c - b;
  17.  
  18.     local right = ac:Cross(ab).unit;
  19.     local up = bc:Cross(right).unit;
  20.     local back = bc.unit;
  21.  
  22.     local height = math.abs(ab:Dot(up));
  23.  
  24.     local w1 = wedge:Clone();
  25.     w1.Size = Vector3.new(0, height, math.abs(ab:Dot(back)));
  26.     w1.CFrame = CFrame.fromMatrix((a + b)/2, right, up, back);
  27.     w1.Parent = workspace;
  28.  
  29.     local w2 = wedge:Clone();
  30.     w2.Size = Vector3.new(0, height, math.abs(ac:Dot(back)));
  31.     w2.CFrame = CFrame.fromMatrix((a + c)/2, -right, up, -back);
  32.     w2.Parent = workspace;
  33.  
  34.     return w1, w2;
  35. end
  36.  
  37. while true do
  38.     local a = workspace.A.Position
  39.     local b = workspace.B.Position
  40.     local c = workspace.C.Position
  41.  
  42.     local wedgeA, wedgeB = draw3dTriangle(a, b, c)
  43.  
  44.     wait()
  45.  
  46.     wedgeA:Destroy()
  47.     wedgeB:Destroy()
  48. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement