Take the 2-minute tour ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

How can I orient a circle that has a position to a 3D object? If I have a 3D object which is a hemisphere, I would like to let the circle be underneath that hemi-sphere and whenever the hemisphere moves, the circle move with the same angle and position, and underneath it.

In other words, I would like to attach a 2D circle to a hemisphere and parallel to it.

share|improve this question
    
That's still not really clear... –  Byte56 Apr 19 '12 at 15:41
    
@byte56, I have edited it. –  Moaz Apr 19 '12 at 15:49
    
Even post-edit I have no idea what you are asking about. –  Josh Petrie Apr 19 '12 at 15:57
    
Your language is very imprecise. What do you mean by orientation? When you say circle, are you talking about a sphere, or some kind of 2d projection, or what? (EDIT) It was actually a little more clear before you deleted everything. –  michael.bartnett Apr 19 '12 at 16:00
    
Can you draw a simple picture of what it would look like perhaps? –  Tim Holt Apr 19 '12 at 16:09
show 4 more comments

1 Answer

You need to have an orientation defined for your object/entity. This is usually an unit vector in 3D, v=(vx,vy,vz). If you have an object oriented bounding box, then you can use that to determine where the "bottom" part of your object is. If not, just consider a "safety" distance/radius from the center of your object. Say this distance is d. Then one can simply find where the circle's center is by using the object's center, the v direction and the d distance:

 CircleCenter = ObjectCenter - d * v

How to draw the circle? It might seem like a difficult task. In 2D, that's trivial: circle(x,y,r) = (r*cos(u) +x, r*sin(u) + y), where u between [0, 360] degs.

In 3D you can draw it in the xOy plane, via its parametric equation: circle(0,0,0,r) = (r*cos(u), r*sin(u), 0)

What to do next? Rotate the circle in such a way that its local Z(up) axis points in the same direction as the v vector. How? Find the rotation that aligns Z with v:

 w = cross((0,0,1), v)
 circle = RodriguesRotation(w, angle(v,(0,0,1)) * (r*cos(u), r*sin(u),0) + CircleCenter

The RodriguesRotation is the general rotation matrix against a w axis by an angle theta. In the picture below, the black arrow is the orientation, the red circle with red orientation arrows is what your circle should look like, and the crimson line is the d distance offset from the object's center.

enter image description here

share|improve this answer
    
I use cinder library and there is no support for the rodriguesRotation –  Moaz Apr 19 '12 at 21:14
    
en.wikipedia.org/wiki/… It's not too difficult to code it though –  teodron Apr 20 '12 at 9:12
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.