Tuesday, November 22, 2022
HomeGame Developmentarithmetic - Discover take a look at rotation with offset

arithmetic – Discover take a look at rotation with offset


I have been attempting to make a operate much like “Discover take a look at rotation” however with an offset. Think about I’ve a pivot and an object connected to that pivot with some location and rotation offset. I wish to rotate the pivot in order that the kid object is going through a goal.

Example

The blue field is the pivot, the grey is the kid object and the crimson is the goal.
I’ve discovered a way that ought to work, however I am having hassle implementing it.

Function
That is the operate that I’ve made.

I’ve requested this query on math stack change and this operate is predicated on this reply that I obtained…

The factors which might be being referred to on this are:

  • B – The kid object location

  • C – Some extent on the road that goes from the kid object alongside its ahead vector

  • D – The goal location

  • O – Origin and in addition the pivot location

…rotate level $D$ about an axis passing via the origin, in order that $D$‘s picture lies on the road $BC$. After we discover this rotation, we’ll simply invert the rotation and apply it to line $BC$, to make it include level $D$.

Because the rotation of level $D$ about any axis passing via the origin, can be one other level that lies on the sphere centered on the origin, and with a radius equal to $OD$, then all now we have to do to search out the picture of level $D$, is intersect the sphere with line $BC$. There might be no intersections, one intersection, or two intersections at most. If there aren’t any intersections, then it’s not attainable to carry out this rotation to fulfill the given situation. In any other case, choose an intersection, name it $D′$ because the picture of $D$. Now we wish to rotate $OD$ into $OD′$, and this may be achieved in an infinite variety of methods, because the axis of rotation just isn’t distinctive, however as a substitute lies within the aircraft whose regular vector is $DD′$ and passing via the midpoint of $DD′$.

Nonetheless, there’s a rotation that makes use of the minimal attainable rotation angle, and that rotation has an axis given by $ODtimes OD’$, and the rotation angle $theta$ is given by:

$$theta = textual content{atan2}bigg( dfrac{OD cdot OD’}^2 ,dfrac ^2 bigg) = textual content{atan2} ( OD cdot OD’ , | OD instances OD’ | )$$

Plugging the equations above into Geogebra I did certainly get the specified end result, however I am having hassle replicating the identical in Unreal.

RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

- Advertisment -
Google search engine

Most Popular

Recent Comments