Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local p1,p2,p3 = Workspace['Point1']['Position'], Workspace['Point2']['Position'], Workspace['Point3']['Position'];
- function AngleBetween(v1, v2)
- return math['deg'](math['acos']( (v1:Dot(v2))/(v1['magnitude'] * v2['magnitude']) ))
- end
- function GetWedge()
- local p = Instance['new']([[WedgePart]], Workspace);
- p['TopSurface'], p['BottomSurface'] = "Smooth", "Smooth";
- p['Anchored'] = true;
- p['FormFactor'] = "Custom";
- --p['Size'] = Vector3['new'](.1,5,5);
- return p;
- end
- function GetPoint()
- local p = Instance['new']("Part", Workspace)
- p.FormFactor = "Symmetric"
- p.BrickColor = BrickColor.Blue()
- p.Size = Vector3.new(1,1,1)
- p.Anchored = true
- return p;
- end
- function DrawLine(to, from)
- --[[
- Required an object
- local f = Instance.new("FloorWire", Workspace)
- f.To = to;
- f.From = from
- f.Color = BrickColor.Yellow();]]
- local r = Instance.new("Part")
- r.FormFactor = "Custom"
- r.Size = Vector3.new(0, 0, (from-to)['magnitude'])
- r.Anchored = true
- r.BrickColor = BrickColor.Yellow();
- r.CFrame = (CFrame.new(to, from))
- r.CFrame = r.CFrame + (r.CFrame.lookVector * r.Size.Z/2)
- r.Parent = Workspace
- end
- function dTriangle(v1,v2,v3)
- local A, B, C = AngleBetween((v2-v1)['unit'], (v3-v1)['unit']), AngleBetween((v1-v2)['unit'], (v3-v2)['unit']), AngleBetween((v1-v3)['unit'], (v2-v3)['unit']);
- local a, b, c = (v3-v2)['magnitude'], (v1-v3)['magnitude'], (v1-v2)['magnitude'];
- DrawLine(v1, v2);
- DrawLine(v2, v3);
- DrawLine(v3, v1);
- if A ~= 90 and B ~= 90 and C ~= 90 then -- no right triangle
- local longest;
- if A > B and A > C then
- local adjacent = math['cos'](math.rad(B)) * c
- local bisector = v2 + ((v3-v2)['unit'] * adjacent);
- local bisector_length = math.sqrt(c^2 - adjacent^2)--(bisector-v1)['magnitude']
- local np = GetPoint()
- np.CFrame = CFrame.new(bisector)
- DrawLine(v1, bisector);
- local w1 = GetWedge();
- local tl = (w1.CFrame * CFrame.Angles(math.rad(90),0,0)).lookVector;
- local mid = v1 + ((v2-v1)['unit'] * c/2);
- local nl = CFrame.new(mid, v3).lookVector
- local d = tl:Dot(nl)/(tl.magnitude * nl.magnitude);
- w1.Size = Vector3.new(0,adjacent, bisector_length);
- w1.CFrame = (CFrame.new(mid) * CFrame.Angles(0,0,math.acos(d)))-- * CFrame.Angles(0,0,-math.pi);
- elseif B > A and B > C then
- local adjacent = math['cos'](math.rad(C)) * a
- local bisector = v3 + ((v1-v3)['unit'] * adjacent);
- local np = GetPoint()
- np.CFrame = CFrame.new(bisector)
- DrawLine(v2, bisector);
- else -- C is greatest angle
- local adjacent = math['cos'](math.rad(A)) * b
- local bisector = v1 + ((v2-v1)['unit'] * adjacent);
- local np = GetPoint()
- np.CFrame = CFrame.new(bisector)
- DrawLine(v3, bisector);
- end
- else -- already a right triangle
- local w = GetWedge();
- if A == 90 then -- point1 is the 90
- --w['CFrame'] = CFrame['new'](v1 ) * CFrame['Angles'](0,math['rad'](-90),math['rad'](90));
- elseif B == 90 then
- else
- end
- end
- print(A,B,C)
- end
- dTriangle(p1,p2,p3);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement