woot3
|
  |
| Joined: 10 Nov 2008 |
| Total Posts: 3599 |
|
|
| 04 Feb 2013 01:35 PM |
I wanted to write a script that creates a triangle (using two wedge parts) between 3 points.
Currently, I am working in 2D as it's a little simpler, but I am then moving to 3D. I guess I'm asking a question, I want to calculate the height of the triangle, even if it's at an angle. Have I got the math to do so correctly?
function createTriangle(a, b, c) local ab = (a-b).magnitude local abx = (b.x-a.x) local bc = (b-c).magnitude local bcx = c.x-b.x local anga,angb = math.asin(bcx/bc),math.asin(abx/ab) local anga,angb = anga < 0 and anga*-1 or anga, angb < 0 and angb*-1 or angb local angc = math.pi-(anga+angb) local h = bc*math.sin(angc) print(h) end
createTriangle(Vector3.new(0,0,0),Vector3.new(5,0,0),Vector3.new(4,5,0)) |
|
|
| Report Abuse |
|
|
TeamDman
|
  |
| Joined: 04 Dec 2009 |
| Total Posts: 897 |
|
|
| 04 Feb 2013 01:44 PM |
Didn't Stravant make something to do the same thing?
"Don't believe everything you read online" - Abraham Lincoln |
|
|
| Report Abuse |
|
|
|
| 04 Feb 2013 01:52 PM |
@Team
But all the other implementations broke down somewhere... |
|
|
| Report Abuse |
|
|
woot3
|
  |
| Joined: 10 Nov 2008 |
| Total Posts: 3599 |
|
|
| 04 Feb 2013 01:56 PM |
That's actually a great help, I'll study his script. I appreciate it! |
|
|
| Report Abuse |
|
|
HotThoth
|
  |
 |
| Joined: 24 Aug 2010 |
| Total Posts: 1176 |
|
|
| 04 Feb 2013 02:39 PM |
Just use linear algebra-- keeps the math a lot simpler, and everything with vectors is happy in ROBLOX anyways. Seriously, though, dot product is magical-- X dot Y gives you the length of X's "shadow" when projected perpendicularly onto Y. This lets you do a lot of cool/tricky things very quickly.
So with triangle ABC and you want to find perpendicular from B down to AC, you could just do the following:
AB = B - A AC = C - A D = (AB:Dot(AC) * AC.unit) + A
Where D is the point on AC where B drops down to to form a right angle. So the height vector would be BD = B - D, with height of BD.magnitude.
I did this pretty quickly; may have made a mistake, but I think that's right.
- HotThoth
~ Think happy Thoths ~ |
|
|
| Report Abuse |
|
|
Alureon
|
  |
| Joined: 15 Dec 2012 |
| Total Posts: 134 |
|
|
| 04 Feb 2013 03:34 PM |
| not advanced noob learn to script |
|
|
| Report Abuse |
|
|
|
| 04 Feb 2013 03:53 PM |
^ I'd like to see some of your work. |
|
|
| Report Abuse |
|
|
Alureon
|
  |
| Joined: 15 Dec 2012 |
| Total Posts: 134 |
|
|
| 04 Feb 2013 04:04 PM |
| print("some of my work. you know, i wrote the original print function in C that is still used by ROBLOX today? ask any admin.") |
|
|
| Report Abuse |
|
|
BenBonez
|
  |
| Joined: 29 Aug 2008 |
| Total Posts: 19362 |
|
| |
|
|
| 04 Feb 2013 04:10 PM |
@Alureon Because C functions are SO hard...
GOBWEY |
|
|
| Report Abuse |
|
|
Alureon
|
  |
| Joined: 15 Dec 2012 |
| Total Posts: 134 |
|
| |
|
booing
|
  |
| Joined: 04 May 2009 |
| Total Posts: 6594 |
|
|
| 04 Feb 2013 04:28 PM |
@alur without raging, we all have no respect for you. you're a lying idiot who can't script properly much less make a hax. go away |
|
|
| Report Abuse |
|
|
|
| 04 Feb 2013 05:41 PM |
Here's one I made a while ago. http://www.roblox.com/Triangle-Tool-item?id=34109637
If I recall correctly, it uses no trigonometry. Avoiding trig will make things so much easier for you. One thing it did was construct a CFrame using the 3x3 rotation matrix. You should look into that.
And one thing to note (this is useful when making your rotation matrix), if you have the lookVector of the front side and the lookVector of the top side, to get the lookVector of the right side, just do frontVector:Cross(topVector). |
|
|
| Report Abuse |
|
|
|
| 04 Feb 2013 05:44 PM |
Learn vector notation and operations, they helpz.
Visual to learn: -Hat thing -Dot product -Cross product -Double absolute value looking thing -Stuff |
|
|
| Report Abuse |
|
|
|
| 04 Feb 2013 05:48 PM |
> And one thing to note (this is useful when making your rotation > matrix), if you have the lookVector of the front side and the > lookVector of the top side, to get the lookVector of the right side, > just do frontVector:Cross(topVector).
I figured out the following myself a very long time ago. I will share with you this golden piece of knowledge: local x,y,z,xx,yx,zx,xy,yy,zy,xz,yz,zz=CFrame:components() position=x,y,z right "lookVector"=xx,xy,xz upward "lookVector"=yx,yy,yz front "lookVector"=zx,zy,zz
k |
|
|
| Report Abuse |
|
|
|
| 04 Feb 2013 05:56 PM |
@Monkey
local X,Y,Z = CFrame.X,CFrame.Y,CFrame.Z local X2,Y2,Z2 = CFrame:toEulerAnglesXYZ()
This will give you the angles of the CFrame. I am sure you already knew this, but oh well. :3 |
|
|
| Report Abuse |
|
|
|
| 04 Feb 2013 06:00 PM |
eww Why would you want angles e.e |
|
|
| Report Abuse |
|
|
|
| 04 Feb 2013 06:02 PM |
| Angles are way more useful than lookvectors. Well, in my opinion they are. |
|
|
| Report Abuse |
|
|
|
| 04 Feb 2013 06:02 PM |
| Angles are way more useful than lookvectors. Well, in my opinion they are. |
|
|
| Report Abuse |
|
|
|
| 04 Feb 2013 06:03 PM |
| Daheck? It double-posted... |
|
|
| Report Abuse |
|
|
|
| 04 Feb 2013 07:31 PM |
| eww... stop... what on earth could you use the angles for!? |
|
|
| Report Abuse |
|
|
Alureon
|
  |
| Joined: 15 Dec 2012 |
| Total Posts: 134 |
|
|
| 05 Feb 2013 10:30 AM |
@booing same thing to you sir. |
|
|
| Report Abuse |
|
|
| |
|