|
| 17 May 2009 02:33 PM |
Could someone help me create a function to reflect a ray, after bouncing off of a plane? (Yes, this IS the correct forum. No one in 'Script Help' would be able to help me. This is very complex) Assuming a ray with lookVector 'r' hit a plane with a outward-facing lookVector 'p', then what would the resulting lookVector of the resulting ray be? ('h')
If someone could help, I can finish my ray-tracer and physics engine. |
|
|
| Report Abuse |
|
|
|
| 17 May 2009 02:38 PM |
| I dont get it . . . and I'm in a tenth grade honors math class, and science |
|
|
| Report Abuse |
|
|
|
| 17 May 2009 03:06 PM |
You won't get into this kind of stuff until you're taking a degree in computer science.
That's going to be a lot of heavy math, good luck. |
|
|
| Report Abuse |
|
|
Connolly
|
  |
| Joined: 28 Mar 2008 |
| Total Posts: 5740 |
|
|
| 17 May 2009 03:07 PM |
| MrDoomBringer how are you in the top 100 posts when I have more post then you and i'm not? |
|
|
| Report Abuse |
|
|
Wyoming
|
  |
| Joined: 05 Feb 2008 |
| Total Posts: 8453 |
|
|
| 17 May 2009 03:46 PM |
| A lot of early accounts like 06 have the Top 100 Posts thing as a glitch, or maybe just cuz's MDB's a Super Mod. Who knows...XD |
|
|
| Report Abuse |
|
|
|
| 17 May 2009 03:48 PM |
| phew then i shouldnt feel bad that i dont know this... |
|
|
| Report Abuse |
|
|
Meelo
|
  |
| Joined: 04 Jul 2008 |
| Total Posts: 14763 |
|
|
| 17 May 2009 03:51 PM |
| Yeah. If you could figure out the degree of slope coming into the plane, I might be able to help you... |
|
|
| Report Abuse |
|
|
|
| 17 May 2009 04:34 PM |
| Yes, Meelo's right. Finding which way it would bounce off (assuming a laser with a mirror) is easy(ier) once you have found the angle that the lookVector is coming from. |
|
|
| Report Abuse |
|
|
| |
|
Meelo
|
  |
| Joined: 04 Jul 2008 |
| Total Posts: 14763 |
|
|
| 17 May 2009 04:52 PM |
| It's trivial in 2D, and you can probably reduce it to a 2D problem. |
|
|
| Report Abuse |
|
|
|
| 17 May 2009 05:44 PM |
| Inverse of the ray's incoming angle |
|
|
| Report Abuse |
|
|
Ozzypig
|
  |
| Joined: 27 Mar 2008 |
| Total Posts: 4906 |
|
|
| 17 May 2009 06:13 PM |
I think you people need to think more 2D right now rather than 3D and use Z as 0 for everything, like MDB said, it's ub3r h4x from this.
Think about a ray coming at a plane, and the ray is coming at an angle of 45 degrees.
We need a full half circle; 180 degrees. So The two sides of the surface are at 0 and 180. That's two. We have the other angle of 45. That's three angles. Take the ray's angle and subtract it from 180 to make it flip to the other side. This case would be 135 degrees. The lines would be:
0, 45, 135, 180. So use some trigonometry (sine, cosine, tangent) to find a looking direction of the new line.
If we find the difference of the thrird subtracted by the second, we get a number that we need. In this case, it's 135 - 45, or 90.
---
Consider this case in 2D.
- A ray is coming from 0,0 heading to 1,0. - A surface/mirror is point 3,-1 to 5, 1 (slope of 1, 45 degree, diagonal). - The ray hits the surface at 4,0. - If you use the special number from above, which is 90, rotate the direction the ray is heading using trig. functions. - We find that the new direction has an infanate slope (is this dangerous!?).
---
I can draw this out....like really good. Anyone interested? |
|
|
| Report Abuse |
|
|
Meelo
|
  |
| Joined: 04 Jul 2008 |
| Total Posts: 14763 |
|
|
| 17 May 2009 07:31 PM |
"- We find that the new direction has an infanate slope (is this dangerous!?). "
Which is why you always check to see if an angle is 0 or pi before you use a tangent. |
|
|
| Report Abuse |
|
|
XlegoX
|
  |
| Joined: 16 Jun 2008 |
| Total Posts: 14955 |
|
|
| 17 May 2009 07:55 PM |
| Yea, separating axis theorem can probably be applied to solve it... |
|
|
| Report Abuse |
|
|
Ozzypig
|
  |
| Joined: 27 Mar 2008 |
| Total Posts: 4906 |
|
|
| 17 May 2009 09:26 PM |
| Well knowing Lua, it handles infinate numbers pretty well. |
|
|
| Report Abuse |
|
|
|
| 17 May 2009 09:49 PM |
For the last time: Ignore the top 100 stuff. It's been broken and not working right since before I joined Roblox.
Edit:
Also, Lua does not handle infinite loops or numbers very well. |
|
|
| Report Abuse |
|
|
MicroUser
|
  |
| Joined: 29 Mar 2009 |
| Total Posts: 3601 |
|
| |
|
Ozzypig
|
  |
| Joined: 27 Mar 2008 |
| Total Posts: 4906 |
|
|
| 18 May 2009 03:37 PM |
Micro, it inverses it, not the same direction. Same angle from the other side, but not direction.
I think Lua can handle enough infinity for a line to be reflected. |
|
|
| Report Abuse |
|
|
|
| 18 May 2009 04:51 PM |
The problem is, I don't know trigonometry, or this would be easier.
I need an actual equation, or I can't underdtand it. XD (I get equations better than literal words) |
|
|
| Report Abuse |
|
|
XlegoX
|
  |
| Joined: 16 Jun 2008 |
| Total Posts: 14955 |
|
|
| 18 May 2009 06:17 PM |
Lol, even if you did know trigonometry it would be far from easier...
This might be helpfull if you're looking for a solid formula:
local vec1, vec2 local ang = math.acos(vec1.unit.x*vec2.unit.x + vec1.unit.y*vec2.unit.y + vec1.unit.z*vec2.unit.z)
where ang is the smallest angle between the two vectors |
|
|
| Report Abuse |
|
|
| |
|
DannyCore
|
  |
| Joined: 25 Apr 2012 |
| Total Posts: 990 |
|
|
| 05 Mar 2013 03:16 PM |
| what the heck was that "NO" for? |
|
|
| Report Abuse |
|
|
Garnished
|
  |
| Joined: 09 Apr 2012 |
| Total Posts: 12695 |
|
|
| 05 Mar 2013 03:59 PM |
@MrDoomBring >Degree in computer science NXTBoy did it. |
|
|
| Report Abuse |
|
|
Garnished
|
  |
| Joined: 09 Apr 2012 |
| Total Posts: 12695 |
|
|
| 05 Mar 2013 03:59 PM |
@MrDoomBringer >Degree in computer science NXTBoy did it. |
|
|
| Report Abuse |
|
|
|
| 05 Mar 2013 04:11 PM |
i was gonna tell everyone about super maths and then
"2009"
:( |
|
|
| Report Abuse |
|
|