# Untitled

Nov 26th, 2020
64
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
1. local Terrain = workspace.Terrain
2.
3. local DrawTriangle = {}
4.
5. local wedge = Instance.new("WedgePart");
6. wedge.Anchored = true;
7. wedge.TopSurface = Enum.SurfaceType.Smooth;
8. wedge.BottomSurface = Enum.SurfaceType.Smooth;
9.
10. function DrawTriangle.Draw(a, b, c, parent)
11.     local edges = {
12.         {longest = (c - a), other = (b - a), origin = a},
13.         {longest = (a - b), other = (c - b), origin = b},
14.         {longest = (b - c), other = (a - c), origin = c}
15.     };
16.
17.     local edge = edges[1];
18.     for i = 2, #edges do
19.         if (edges[i].longest.magnitude > edge.longest.magnitude) then
20.             edge = edges[i];
21.         end
22.     end
23.
24.     local theta = math.acos(edge.longest.unit:Dot(edge.other.unit));
25.     local w1 = math.cos(theta) * edge.other.magnitude;
26.     local w2 = edge.longest.magnitude - w1;
27.     local h = math.sin(theta) * edge.other.magnitude;
28.
29.     local p1 = edge.origin + edge.other * 0.5;
30.     local p2 = edge.origin + edge.longest + (edge.other - edge.longest) * 0.5;
31.
32.     local right = edge.longest:Cross(edge.other).unit;
33.     local up = right:Cross(edge.longest).unit;
34.     local back = edge.longest.unit;
35.
36. local cf1 = CFrame.new(
37.         p1.x, p1.y, p1.z,
38.         -right.x, up.x, back.x,
39.         -right.y, up.y, back.y,
40.         -right.z, up.z, back.z
41.     );
42.
43. local cf2 = CFrame.new(
44.         p2.x, p2.y, p2.z,
45.         right.x, up.x, -back.x,
46.         right.y, up.y, -back.y,
47.         right.z, up.z, -back.z
48.     );
49.
50.     -- put it all together by creating the wedges
51.
52.     --local wedge1 = Terrain:FillWedge(cf1, Vector3.new(0.2, h, w1), Enum.Material.Grass)
53.
54.     --local wedge2 = Terrain:FillWedge(cf2, Vector3.new(0.2, h, w2), Enum.Material.Grass)
55.
56.     local wedge1 = wedge:Clone();
57.     wedge1.Size = Vector3.new(0.2, h, w1);
58.     wedge1.CFrame = cf1;
59.     wedge1.Parent = parent;
60.
61.     local wedge2 = wedge:Clone();
62.     wedge2.Size = Vector3.new(0.2, h, w2);
63.     wedge2.CFrame = cf2;
64.     wedge2.Parent = parent;
65. end
66.
67. --draw3dTriangle(Vector3.new(-11.036, 2.293, -4.759), Vector3.new(-11.036, 2.293, 2.286), Vector3.new(-18.468, 2.293, 2.286), workspace)
68. --draw3dTriangle(Vector3.new(-11.036, 2.293, -4.759), Vector3.new(-18.468, 2.293, 2.286), Vector3.new(-18.468, 0.155, -5.013), workspace)
69.
70. return DrawTriangle
71.