• Announcements

    • khawk

      Download the Game Design and Indie Game Marketing Freebook   07/19/17

      GameDev.net and CRC Press have teamed up to bring a free ebook of content curated from top titles published by CRC Press. The freebook, Practices of Game Design & Indie Game Marketing, includes chapters from The Art of Game Design: A Book of Lenses, A Practical Guide to Indie Game Marketing, and An Architectural Approach to Level Design. The GameDev.net FreeBook is relevant to game designers, developers, and those interested in learning more about the challenges in game development. We know game development can be a tough discipline and business, so we picked several chapters from CRC Press titles that we thought would be of interest to you, the GameDev.net audience, in your journey to design, develop, and market your next game. The free ebook is available through CRC Press by clicking here. The Curated Books The Art of Game Design: A Book of Lenses, Second Edition, by Jesse Schell Presents 100+ sets of questions, or different lenses, for viewing a game’s design, encompassing diverse fields such as psychology, architecture, music, film, software engineering, theme park design, mathematics, anthropology, and more. Written by one of the world's top game designers, this book describes the deepest and most fundamental principles of game design, demonstrating how tactics used in board, card, and athletic games also work in video games. It provides practical instruction on creating world-class games that will be played again and again. View it here. A Practical Guide to Indie Game Marketing, by Joel Dreskin Marketing is an essential but too frequently overlooked or minimized component of the release plan for indie games. A Practical Guide to Indie Game Marketing provides you with the tools needed to build visibility and sell your indie games. With special focus on those developers with small budgets and limited staff and resources, this book is packed with tangible recommendations and techniques that you can put to use immediately. As a seasoned professional of the indie game arena, author Joel Dreskin gives you insight into practical, real-world experiences of marketing numerous successful games and also provides stories of the failures. View it here. An Architectural Approach to Level Design This is one of the first books to integrate architectural and spatial design theory with the field of level design. The book presents architectural techniques and theories for level designers to use in their own work. It connects architecture and level design in different ways that address the practical elements of how designers construct space and the experiential elements of how and why humans interact with this space. Throughout the text, readers learn skills for spatial layout, evoking emotion through gamespaces, and creating better levels through architectural theory. View it here. Learn more and download the ebook by clicking here. Did you know? GameDev.net and CRC Press also recently teamed up to bring GDNet+ Members up to a 20% discount on all CRC Press books. Learn more about this and other benefits here.
Sign in to follow this  
Followers 0
_swx_

Finding vector perpendicular to line in 3D

9 posts in this topic

I need a robust method for finding any vector that is perpendicular to a line in 3D. I know that there is an infinite number of them, but I just need any one of them.
0

Share this post


Link to post
Share on other sites
You know that the dot product between your unknown vector (x,y,z) and the line direction vector (A,B,C) is 0, which gives you the equation Ax + By + Cz = 0. If you let 'x' and 'y' be 1, then 'z' is -(A+B)/C. The issue is that C might be zero, so you want to make sure and solve for the component (by plugging in 'x' and 'z' instead and solving for 'y', etc.) whose corresponding value in the line direction vector isn't 0 (choosing the one largest in magnitude would help stabilize the division). From there you can normalize the vector and be done.

Another approach is to find which component in the line direction vector is closest to zero, and create a vector where that component value is 1 and the rest are 0. You can then use something like Gram-Schmidt to find the perpendicular vector.

Unfortunately, the hairy ball theorem tells us that you need conditional logic to make this process work for any given line direction, because there is no continuous function we can use.
1

Share this post


Link to post
Share on other sites
Solving the dotproduct equation was my initial solution to the problem. I was hoping for a prettier solution, but I guess it'll have to do. Thanks for the interesting wikipedia link (Hary ball theorem) :)
0

Share this post


Link to post
Share on other sites
Quote:
Original post by _swx_
Solving the dotproduct equation was my initial solution to the problem. I was hoping for a prettier solution, but I guess it'll have to do. Thanks for the interesting wikipedia link (Hary ball theorem) :)
I'm not sure if Zipster already mentioned this, but one solution is to find the element of the line direction vector with the smallest magnitude (as Zipster mentioned), and then cross the direction vector with the cardinal basis vector ([1, 0, 0], [0, 1, 0], or [0, 0, 1]) that corresponds to this element. (This is the method I prefer for computing an arbitrary vector perpendicular to another vector, an operation commonly needed for billboarding, decals, and so forth.)
2

Share this post


Link to post
Share on other sites
Thanks for the replies. I'm going to use the cross-product solution since it produces nice vectors :)
0

Share this post


Link to post
Share on other sites
Quote:
Original post by Zipster
Unfortunately, the hairy ball theorem tells us that you need conditional logic to make this process work for any given line direction, because there is no continuous function we can use.


Why? The space here is RP^2, not S^2... granted, that's just S^2 with antipodes identified, but still, it doesn't jump out at me that this should automatically carry over... (But then, lots of things that should jump out at me seem not to...)

Actually, here you go: The hairy ball theorem says you can't have a smooth nonvanishing vector field on S^2. However, just ONE vanishing point is enough. E.g., consider a constant vector field on the plane multiplied by a radial falloff and mapped to the sphere by stereographic projection.

So now, here's a way to get a continuous (albeit nonsmooth) nonvanishing vector field on RP^2: Since each point on RP^2 is identified with two points on the sphere, just take whichever of the two vectors (from the vector field) has larger norm.

Then, there's always an analytic function arbitrarily close to any continuous function (constructively: Run the heat equation for epsilon seconds), so you can now get a smooth vector field from the continuous one constructed above.

(An alternate construction could have used some kind of "soft max" operator.)

Have I missed something?

[Edited by - Emergent on June 1, 2010 4:07:20 PM]
0

Share this post


Link to post
Share on other sites
I'm going to admit right off the bat that you probably know more about the underlying mathematics than I do, since I haven't studied projective spaces in much depth, but...

Quote:
Original post by Emergent
So now, here's a way to get a continuous (albeit nonsmooth) nonvanishing vector field on RP^2: Since each point on RP^2 is identified with two points on the sphere, just take whichever of the two vectors (from the vector field) has larger norm.

Wouldn't this require a conditional to determine the one with the larger norm?

Quote:
Have I missed something?

Probably not :) I've honestly just never seen a solution to this problem that didn't at some point require conditional logic in one way or another, due to the nature of the tangent field. But I'm certainly open to the possibility that one exists.
0

Share this post


Link to post
Share on other sites
*sigh*; I really need to think/read more before posting...

From Wikipedia:
Quote:
A consequence of the hairy ball theorem is that any continuous function that maps a sphere into itself has either a fixed point or a point that maps onto its own antipodal point. This can be seen by transforming the function into a tangential vector field as follows.


Hence, any smooth map from RP^2 to RP^2 has a fixed point. At the fixed point,

f(p)=p || p

so there's no way to have f(p) perpendicular to p for all p.

They even give the proof right there...
1

Share this post


Link to post
Share on other sites

If you rotate your direction vector twice (90° arround x-axis and 90° around y-axis) you get an arbitrary vector that is linearly independent of the direction vector. Then you retrieve a perpendicuar vector to those two vectors via cross product.

 

Or is there an error in reasoning for that method?

 

 

Edit: Oh yes there are cases where this fails -.- e.g. (1,0,-1) turned arround x-axis by 90° then turned arround y-axis by 90° results in the same vector. But can it still fail when turned by different angles like 30° and 60° ?

Edited by hageldave
-1

Share this post


Link to post
Share on other sites
Guest
This topic is now closed to further replies.
Sign in to follow this  
Followers 0