stravant
|
  |
 |
| Joined: 22 Oct 2007 |
| Total Posts: 2893 |
|
|
| 02 Sep 2012 11:32 PM |
Make a function that takes a vector, and returns a new vector that has a different direction than it, and is not just the negation of it.
Any vector will do, it just has to be different, that's it.... and of course it has to work for _all_ non-zero inputs.
It's easy if you allow branching:
function Different(v) if v.unit == Vector3.new(1,0,0) then return Vector3.new(0,1,0) else return Vector3.new(1,0,0) end end
But can you find a solution which does not involve branching? I'm not even sure if there is one. |
|
|
| Report Abuse |
|
|
Legend26
|
  |
| Joined: 08 Sep 2008 |
| Total Posts: 10586 |
|
|
| 02 Sep 2012 11:54 PM |
| Can't you just use math.random()? |
|
|
| Report Abuse |
|
|
AdvRobot
|
  |
| Joined: 09 Aug 2012 |
| Total Posts: 172 |
|
| |
|
|
| 03 Sep 2012 12:09 AM |
If(v.X != 0 && v.Y == 0 && && v.Z != 0) { Return new Vector3(0b000000000,1,0); } else { Return new Vector3(0,0,1); }
Or am I missing the point. |
|
|
| Report Abuse |
|
|
| |
|
stravant
|
  |
 |
| Joined: 22 Oct 2007 |
| Total Posts: 2893 |
|
|
| 03 Sep 2012 12:31 AM |
"Can't you just use math.random()?"
Even assuming that math.random does not use branching, it may still fail, since it can end up returning what you started with. |
|
|
| Report Abuse |
|
|
|
| 03 Sep 2012 02:02 AM |
function a(vector) return (-vector + vector/2)+1 --Add one to all coordinates end
I'm not sure if that works completely, but it's the best I've got so far. |
|
|
| Report Abuse |
|
|
NXTBoy
|
  |
| Joined: 25 Aug 2008 |
| Total Posts: 4533 |
|
|
| 03 Sep 2012 02:32 AM |
Does this work?
Vector3.new(0,1,0):Cross(v) + Vector3.new(1,0,0):Cross(v) |
|
|
| Report Abuse |
|
|
8SunTzu8
|
  |
| Joined: 30 Sep 2011 |
| Total Posts: 8199 |
|
|
| 03 Sep 2012 07:00 AM |
@NXT
It would need to be a function.
I think finding a perpendicular vector is the best way, and it seems like that's what NXT was doing.
Become an Innovator: [ http://www.roblox.com/Forum/ShowPost.aspx?PostID=77116209 ] |
|
|
| Report Abuse |
|
|
Anaminus
|
  |
 |
| Joined: 29 Nov 2006 |
| Total Posts: 5945 |
|
|
| 03 Sep 2012 07:10 AM |
return Vector3.new(0,0,0)
- direction isn't the same as the input - isn't the negation of the input - works for all non-zero inputs |
|
|
| Report Abuse |
|
|
agent767
|
  |
| Joined: 03 Nov 2008 |
| Total Posts: 4181 |
|
|
| 03 Sep 2012 07:53 AM |
A null-vector isn`t a direction-vector.
|
|
|
| Report Abuse |
|
|
|
| 03 Sep 2012 08:06 AM |
Oh wait..
You're wanting it to have the same direction of the input... qq
Nevermind then, lol.
☜▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬☜☆☞▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬☞ - Candymaniac, a highly reactive substance. |
|
|
| Report Abuse |
|
|
agent767
|
  |
| Joined: 03 Nov 2008 |
| Total Posts: 4181 |
|
|
| 03 Sep 2012 08:12 AM |
My solution would be:
return Vector3.new(1,1,v.unit.Z+1).unit |
|
|
| Report Abuse |
|
|
|
| 03 Sep 2012 08:34 AM |
| return v + v.unit:isClose(Vector3.new(1,1,1):Cross(v:Dot(Vector3.new(0,0,0)))) and Vector3.new(1,0,1):Lerp(v):Dot(v) or Vector3.new(0,1,v.unit.magnitude) |
|
|
| Report Abuse |
|
|
booing
|
  |
| Joined: 04 May 2009 |
| Total Posts: 6594 |
|
|
| 03 Sep 2012 09:06 AM |
function newvec(v) n = Vector3.new(math.random(1,2),math.random(1,2),math.random(1,2)) if n==v then return newvec(v) end return n end I win? |
|
|
| Report Abuse |
|
|
zars15
|
  |
| Joined: 10 Nov 2008 |
| Total Posts: 9999 |
|
|
| 03 Sep 2012 09:10 AM |
Ummm
repeat lolwhat = math.random() c = 0 c = c + 1 if c == 100 then wait() end until lolwhat ~= v
|
|
|
| Report Abuse |
|
|
|
| 03 Sep 2012 09:23 AM |
Uhm, you failed a bit.
c = 0 repeat lolwhat = math.random() c = c + 1 if c == 100 then wait() end until lolwhat ~= v |
|
|
| Report Abuse |
|
|
zars15
|
  |
| Joined: 10 Nov 2008 |
| Total Posts: 9999 |
|
| |
|
zars15
|
  |
| Joined: 10 Nov 2008 |
| Total Posts: 9999 |
|
|
| 03 Sep 2012 09:24 AM |
| Still, i don't belive that it would take 100 attempts to get random number. |
|
|
| Report Abuse |
|
|
TaslemGuy
|
  |
| Joined: 10 Jun 2009 |
| Total Posts: 12174 |
|
|
| 03 Sep 2012 10:40 AM |
Take the cross product of the vector and the vector rotated by some amount.
|
|
|
| Report Abuse |
|
|
TaslemGuy
|
  |
| Joined: 10 Jun 2009 |
| Total Posts: 12174 |
|
|
| 03 Sep 2012 10:41 AM |
| That doesn't quite work either... |
|
|
| Report Abuse |
|
|
TaslemGuy
|
  |
| Joined: 10 Jun 2009 |
| Total Posts: 12174 |
|
|
| 03 Sep 2012 10:44 AM |
(a `cross` (a+<1,0,0>)) + (a `cross` (a+<0,1,0>))
I can't think of a proof that this works, but I think it might. |
|
|
| Report Abuse |
|
|
agent767
|
  |
| Joined: 03 Nov 2008 |
| Total Posts: 4181 |
|
|
| 03 Sep 2012 10:46 AM |
Protip: Don`t use math.random.
@booing That`s exactlly what lego didn`t want. No if and such sorcery. @zars same thing.
|
|
|
| Report Abuse |
|
|
zars15
|
  |
| Joined: 10 Nov 2008 |
| Total Posts: 9999 |
|
|
| 03 Sep 2012 10:49 AM |
My mind: "Efficiency? What's that?" Soooo... Yeah :D |
|
|
| Report Abuse |
|
|
TaslemGuy
|
  |
| Joined: 10 Jun 2009 |
| Total Posts: 12174 |
|
|
| 03 Sep 2012 10:59 AM |
Suppose you can do "max" without branching:
{x,y,z}
-> {max (x,y,z) + 1, max (x,y,z) + 0.5, max(x,y,z)}.unit
Case 1: x >= y and x >= z.
Then {x+1,x+0.5,x}.magnitude = (x+1)^2+(x+0.5)^2+x^2
= 3x^2 + 3x + 1.25 = m
We want to show that:
{(x+1) / m , (x+0.5) / m, x/m} ~= {x,y,z}.
(x+1)/m = x:
(x+1) = mx, x - mx = -1 x(1-m) = -1 x = 1/(m-1) = 1/(3x^2 + 3x + 0.25)
3x^3 + 3x^2 + 0.25x - 1 = 0
I leave the remainder of the proof as an exercise for the reader. |
|
|
| Report Abuse |
|
|