FusiaOS
|
  |
| Joined: 11 Aug 2013 |
| Total Posts: 99 |
|
|
| 14 Aug 2013 11:26 PM |
Ok, so I am working on a script similar to MrNicNac's old triangle algorithm except im making my own... Basically I can get the midpoint of the triangle and all that mumbo jumbo.... I just don't know how to rotate the triangle to work properly...... My code is below...
p0 = workspace.Part1.Position; p1 = workspace.Part2.Position; p2 = workspace.Part3.Position; --[[ ignore this i was using it for reference and in the forum it will be messed up. p0 /C\ a/ | \b / h \ /B__|__A\ p1 c p2 ]]
s1 = (p0-p1).magnitude; --a s2 = (p0-p2).magnitude; --b s3= (p1-p2).magnitude; --c perimeter = (s1+s2+s3)/2; area = math.sqrt(perimeter*(perimeter-s1)*(perimeter-s2)*(perimeter-s3))
local c, a, b; local find = math.max(s1,s2,s3); if(find==s1)then c = s1; a= s2; b = s3; elseif(find == s2)then c = s2; a= s3; b = s1; elseif(find == s3)then c = s3; a= s1; b = s2; end height = area/(1/2 * c); h = height;
angleB = math.asin(h/a); angleA = math.asin(h/b); angleC = math.rad(180)-angleB-angleA;
angleC1 = math.rad(180)-angleB-math.rad(90); lengthC1 = math.tan(angleC1)*h; midpoint = p1 + (p2-p1).unit*lengthC1; print(lengthC1); t1Pos = p1 + (p2-p1).unit*(lengthC1/2) + (p0-midpoint).unit*(height/2); t2Pos = p2 + (p1-p2).unit*((c-lengthC1)/2) + (p0-midpoint).unit*(height/2);
w= Instance.new("WedgePart"); w2 = w:Clone(); w.Size = Vector3.new(0.2,height,lengthC1); w.CFrame = CFrame.new(t1Pos,Vector3.new(p1.x,p1.y+height/2,p1.z)); w2.Size = Vector3.new(0.2,height,c-lengthC1); w2.CFrame = CFrame.new(t2Pos,Vector3.new(p2.x,p2.y+height/2,p2.z)); w.Parent = workspace; w2.Parent = workspace; w.Anchored = true; w2.Anchored = true; |
|
|
| Report Abuse |
|
|
FusiaOS
|
  |
| Joined: 11 Aug 2013 |
| Total Posts: 99 |
|
|
| 14 Aug 2013 11:37 PM |
| Why does stuff gotta be so complicated lol... |
|
|
| Report Abuse |
|
|
Oysi
|
  |
| Joined: 06 Jul 2009 |
| Total Posts: 9058 |
|
| |
|
MHebes
|
  |
| Joined: 04 Jan 2013 |
| Total Posts: 2278 |
|
|
| 15 Aug 2013 01:32 AM |
I literally had studio open looking at someone's triangle tool and was about to come here to ask why he put his vectors into the rotation matrix directly and found this at the top of the page... Thank you oysi :]
~ Oh, I'm sorry, did I break your concentration? ~ |
|
|
| Report Abuse |
|
|
ENET
|
  |
| Joined: 01 Jan 2010 |
| Total Posts: 4820 |
|
|
| 15 Aug 2013 08:53 AM |
| Can you explain (A-B):Cross(C-B) and tell me what it does and how it works? |
|
|
| Report Abuse |
|
|
Oysi
|
  |
| Joined: 06 Jul 2009 |
| Total Posts: 9058 |
|
| |
|
FusiaOS
|
  |
| Joined: 11 Aug 2013 |
| Total Posts: 99 |
|
|
| 15 Aug 2013 09:46 AM |
Ok thanks, I have completed the model.... It required a little more work, when the method is finding the base of the triangle I had originally forgot to rotate the points of the triangle... I have now done so... Please take a look and tell me what you think Oysi.
http://www.roblox.com/item.aspx?id=126563429
That is the model... Also would you say my version is more efficient then MrNicNac's? |
|
|
| Report Abuse |
|
|
FusiaOS
|
  |
| Joined: 11 Aug 2013 |
| Total Posts: 99 |
|
|
| 15 Aug 2013 09:56 AM |
Also, so about the matrix thing....
z is considered the back and what you did is you basically took the x and y direction and crossed them to get the z direction? |
|
|
| Report Abuse |
|
|
MrNicNac
|
  |
| Joined: 29 Aug 2008 |
| Total Posts: 26567 |
|
|
| 15 Aug 2013 09:58 AM |
"z is considered the back and what you did is you basically took the x and y direction and crossed them to get the z direction?"
Basically, yeah. Since the matrix has to be all perpendicular. However, if you only had one vector and wanted to make a matrix. That is where the fun begins.
Z is considered the front though. |
|
|
| Report Abuse |
|
|
FusiaOS
|
  |
| Joined: 11 Aug 2013 |
| Total Posts: 99 |
|
|
| 15 Aug 2013 10:24 AM |
Back/Front both are connected lol....
Anyways, I have made this into a plugin called Tri-Fusia located at: http://www.roblox.com/item.aspx?id=126566777
I'm not sure, but I think my methods are more efficient than yours MrNicNac... given you did create yours like forever ago, and yours inspired me lol.
The gui in the plugin(executable code) is by Owen0202 from his TriangleStudio plugin that uses MrNicNac's algorithm, however, I am using it for the time being until I design a fully operational plugin out of this.
It is already better than Owen's though.... His undo feature only allowed you do delete the last triangle you made. Mine will go as far back as to the time you opened the place and loaded the script.
Please check it out guys and give me your suggestions. |
|
|
| Report Abuse |
|
|
MrNicNac
|
  |
| Joined: 29 Aug 2008 |
| Total Posts: 26567 |
|
|
| 15 Aug 2013 10:59 AM |
"I'm not sure, but I think my methods are more efficient than yours MrNicNac... given you did create yours like forever ago, and yours inspired me lol."
That's nice and all, but it's not my algorithm. |
|
|
| Report Abuse |
|
|
booing
|
  |
| Joined: 04 May 2009 |
| Total Posts: 6594 |
|
|
| 15 Aug 2013 11:13 AM |
| i only know rectangular trigonometry so i cant help sry |
|
|
| Report Abuse |
|
|
FusiaOS
|
  |
| Joined: 11 Aug 2013 |
| Total Posts: 99 |
|
|
| 15 Aug 2013 11:59 AM |
@MrNicNac didn't you create it? I thought you did anyways... or did you just port it?
Anyways guys, Version 1.1.0 is released at: http://www.roblox.com/item.aspx?id=126576415 It now determines if a triangle is a right angle or not and then determines if one triangle is needed or two...
This really won't affect things too much, but occasionally i had built right angles on a map and it would make two where it could have just made one :)
Now that is problem no more. |
|
|
| Report Abuse |
|
|
Oysi
|
  |
| Joined: 06 Jul 2009 |
| Total Posts: 9058 |
|
| |
|
FusiaOS
|
  |
| Joined: 11 Aug 2013 |
| Total Posts: 99 |
|
|
| 15 Aug 2013 01:45 PM |
| What do you mean vector approach? |
|
|
| Report Abuse |
|
|
Oysi
|
  |
| Joined: 06 Jul 2009 |
| Total Posts: 9058 |
|
| |
|
FusiaOS
|
  |
| Joined: 11 Aug 2013 |
| Total Posts: 99 |
|
|
| 15 Aug 2013 01:54 PM |
| I don't really use trig except to get angles and lengths. |
|
|
| Report Abuse |
|
|
MHebes
|
  |
| Joined: 04 Jan 2013 |
| Total Posts: 2278 |
|
|
| 15 Aug 2013 02:49 PM |
That's what he's saying - don't do that :P Here's a function I came up with yesterday when I saw this thread - no trig :3
function CreateTriangle(p1,p2,p3,properties) local wedge1 = Instance.new("WedgePart") if properties then for i,v in pairs(properties) do pcall(function() wedge1[i] = v end) end end wedge1.TopSurface,wedge1.BottomSurface,wedge1.FrontSurface,wedge1.BackSurface,wedge1.RightSurface,wedge1.LeftSurface = 10,10,10,10,10,10 wedge1.formFactor = "Custom" local found = false while not found do if (p3-p1).magnitude < math.max((p3-p2).magnitude,(p2-p1).magnitude) then p1,p2,p3 = p3,p1,p2 else found = true end end local d = Ray.new(p1,(p3-p1).unit):ClosestPoint(p2) wedge1.Size = Vector3.new(0.2,(p2-d).magnitude,(p1-d).magnitude) local vec1 = (p2-d).unit local vec2 = (d-p1).unit local vec3 = vec1:Cross(vec2).unit local pos = p1:lerp(p2,0.5) wedge1.CFrame = CFrame.new(pos.x,pos.y,pos.z,vec3.x,vec1.x,vec2.x,vec3.y,vec1.y,vec2.y,vec3.z,vec1.z,vec2.z) local wedge2 = Instance.new("WedgePart") wedge2.formFactor = "Custom" wedge2.Size = Vector3.new(0.2,(p2-d).magnitude,(p3-d).magnitude) local vec1 = (p2-d).unit local vec2 = (d-p3).unit local vec3 = vec1:Cross(vec2).unit local pos = p3:lerp(p2,0.5) if properties then for i,v in pairs(properties) do pcall(function() wedge2[i] = v end) end end wedge2.TopSurface,wedge2.BottomSurface,wedge2.FrontSurface,wedge2.BackSurface,wedge2.RightSurface,wedge2.LeftSurface = 10,10,10,10,10,10 wedge2.CFrame = CFrame.new(pos.x,pos.y,pos.z,vec3.x,vec1.x,vec2.x,vec3.y,vec1.y,vec2.y,vec3.z,vec1.z,vec2.z) if not properties.Anchored then local weld = Instance.new("Weld",wedge1) weld.Part0 = wedge1 weld.Part1 = wedge2 weld.C0 = wedge1.CFrame:inverse() * wedge2.CFrame end wedge1.Parent = Workspace wedge2.Parent = Workspace end
~ Oh, I'm sorry, did I break your concentration? ~ |
|
|
| Report Abuse |
|
|
FusiaOS
|
  |
| Joined: 11 Aug 2013 |
| Total Posts: 99 |
|
|
| 15 Aug 2013 03:25 PM |
| I'd rather use trigonometry then nasty raycasting... bleh! |
|
|
| Report Abuse |
|
|
Oysi
|
  |
| Joined: 06 Jul 2009 |
| Total Posts: 9058 |
|
| |
|
FusiaOS
|
  |
| Joined: 11 Aug 2013 |
| Total Posts: 99 |
|
|
| 15 Aug 2013 03:47 PM |
| It is really haxy that away... |
|
|
| Report Abuse |
|
|
MHebes
|
  |
| Joined: 04 Jan 2013 |
| Total Posts: 2278 |
|
|
| 15 Aug 2013 04:42 PM |
Are you referring to how I get 'd'? It finds the point where the two right angles will meet in one line. How is trig better ._.
~ Oh, I'm sorry, did I break your concentration? ~ |
|
|
| Report Abuse |
|
|
FusiaOS
|
  |
| Joined: 11 Aug 2013 |
| Total Posts: 99 |
|
|
| 15 Aug 2013 04:47 PM |
| Trig is an exact science.... raycasting is not. There are variables such as other parts getting in the way and what not. |
|
|
| Report Abuse |
|
|
MHebes
|
  |
| Joined: 04 Jan 2013 |
| Total Posts: 2278 |
|
|
| 15 Aug 2013 06:24 PM |
I used to have that misconception too. When you use Ray.new, it's basically just sending a vector in whatever direction you describe, with whatever origin you describe, but you can do fancy things like :ClosestPoint(). The only way a part in the way would affect it is if you were to use Workspace:FindPartOnRay(). Other than that though, it's nearly the exact same as a vector.
~ Oh, I'm sorry, did I break your concentration? ~ |
|
|
| Report Abuse |
|
|
FusiaOS
|
  |
| Joined: 11 Aug 2013 |
| Total Posts: 99 |
|
|
| 15 Aug 2013 10:45 PM |
| I'd rather stick to exact sciences.... using math, and not object oriented code. |
|
|
| Report Abuse |
|
|