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.

  • \$\begingroup\$ That's still not really clear... \$\endgroup\$ – MichaelHouse Apr 19 '12 at 15:41
  • \$\begingroup\$ @byte56, I have edited it. \$\endgroup\$ – Ahmed Saleh Apr 19 '12 at 15:49
  • \$\begingroup\$ Even post-edit I have no idea what you are asking about. \$\endgroup\$ – user1430 Apr 19 '12 at 15:57
  • \$\begingroup\$ 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. \$\endgroup\$ – michael.bartnett Apr 19 '12 at 16:00
  • \$\begingroup\$ Can you draw a simple picture of what it would look like perhaps? \$\endgroup\$ – Tim Holt Apr 19 '12 at 16:09

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) = (rcos(u) +x, rsin(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) = (rcos(u), rsin(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

  • \$\begingroup\$ I use cinder library and there is no support for the rodriguesRotation \$\endgroup\$ – Ahmed Saleh Apr 19 '12 at 21:14
  • \$\begingroup\$ en.wikipedia.org/wiki/… It's not too difficult to code it though \$\endgroup\$ – teodron Apr 20 '12 at 9:12

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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