#Quick question what is the non dumb way
1 messages ยท Page 1 of 1 (latest)
I want to rotate position around pivot x number of times.
@violet heart yeah, but using uniy's mathematics package.
oh, ok then
That only works for transforms. I have points. And more importantly it doesn't solve the issue.
Please at least read their question before answering lol
It is clearly not using transforms
var rotRelative = Quaternion.Inverse(B) * A;
wait me for answer bro
- find rotate relative with Quaternion inverse(B) * A
@tacit shuttle you actually make relativePosition the same times amount of times
float3 relativePosition = position - pivot;
Let me try to give more context. I have a list of equality distant points. And I need the points to stay equality distant.
The only way I have found to do that while applying a rotation is to apply the rotation multiple times for each point. So rotate it once for the first point, 2 times for the second, 3 times for the third, etc.
What do you mean?
cause I do not see none of position and/or pivot values changed, if I am not blind of course
this my code. you can convert it
you must find rot relative, local pos offset
and apply it
The transformed position is returned
try my code and convert to native code
This is what I am doing for context
IK ?
No, IK is different
why
I need to 'multiply' a quaternion rotation by x. That is my issue
oh wait
my code is just solve relative rotate around by pivot
so do you want do rot around by pivot at X time?
// I want to apply the rotation multiple times. I feel like you should be able to do something like rotation * times and get the same result. But, maybe I am wrong and just not thinking of it properly.
Yeah
so i want scatter
example do you want rotate obj range box
from origin
call func dRotate(pos, pivot,rot = 45 angle, count = 2)
is correct?
Yes, that is correct
yes, it is like float3 relativePosition = theSamePosition; in the loop
Yeah I just noticed my code I posted doesn't even work properly
try to print it and you gonna see it
yep
so maybe you can provide a better way for your code for us to understand what should it execute?
Yeah, here is just the actually code. Chain is basically just a list of float3 + quaternions
// This is the one that I want smoothly create acurve from fromIndex to toIndex.
public static void SmoothRotate<T>(this T chain, int fromIndex, int toIndex, quaternion rotation)
where T : IChain
{
for (int i = fromIndex + 1; i <= toIndex; i++)
{
// This is really ugly looking to do and not very great performance wise.
Rotate(chain, i, rotation);
}
}
// This rotates a single point, all points after keep there relative position.
public static void Rotate<T>(this T chain, int index, quaternion rotation) where T : IChain
{
ChainNode targetNode = chain[index];
// Reposition all of the points down the chain from the specified index.
for (int i = index + 1; i < chain.Count; i++)
{
ChainNode node = chain[i];
float3 relativePosition = node.Position - targetNode.Position;
float3 rotatedPosition = math.mul(rotation, relativePosition);
node.Position = targetNode.Position + rotatedPosition;
chain[i] = node;
}
}
quaterion is the unity Mathematics implementation of Quaternion. You can just use the Vector3, and other APIs and I can convert them to the mathematics API
like math.mul(rotation, relativePosition); is rotation * relativePosition
oh, ok, sorry for my lack of knowledge in this sphere
No problem!
so why don't you just do rotation * relativePosition?
or you cannot do that in this case?
Because the API doesn't have that and wants you to use the method instead ๐คทโโ๏ธ
It does the same thing
oke
I don't understand. But the code I originally posted doesn't even work. You can look at the code I just posted to understand more what I am actually doing
The code I just posted does work. The code I originally posted with my question does not work.
yeah, ok
but you do this stuff in Unity?
Yeah
I wonder why you do use float3 then, but ok
Because it used more optimized when using the Burst compiler
him use jobs system
Hmm have you tried multiplying the rotation by another rotation?
Like if you added to the rotation between each iteration
If this is confusing then just nvm, I mightve misunderstood. But I think I understand what your current code does
Maybe something like rotation = mul(rotation, rotation) between each iteration or is that crazy?
Hmm... let me try
I do feel like you are right, something like this. But uhhh, not exactly this haha
I made a quick prototype
(Its animated kinda like yours but i cant be arsed to record)
I tried with Quaternion * Quaternion first but got similiar results to your most recent GIF @tacit shuttle
Incrementing a float for the angle works better
This is just what I threw together for testingcs float angle = 0f; var pos = Vector3.zero; var positions = new Vector3[10]; for (int i = 0; i < 10; i++) { positions[i] = (Vector3) Event.current.mousePosition - pos; Quaternion rot = Quaternion.Euler(0, 0, -angle); angle += 60f * Mathf.PingPong(GGTime.GetUITime(), 1f); pos += rot * Vector3.up * 25f; } Handles.color = Color.red; Handles.DrawAAPolyLine(5, positions);
Lemme know if theres something I need to clarify and/or if this is even what you wanted
Really the key part here is just this Quaternion rot = Quaternion.Euler(0, 0, -angle); and incrementing the angle in each iteration
Ah actually this works too, just don't be dumb like me and multiply it with itself, but instead with another constant Quaternion like Quaternion.Euler(0, 0, anglePerIteration)
with out loop
simple solve just make rotate around with pivot
and rotation == apply rotationEulerAngle * count
is correct?
Heres a cleaner version of minecs var positions = new Vector3[10]; var pos = Vector3.zero; var rotAdd = Quaternion.Euler(0, 0, anglePerPoint); var rot = Quaternion.identity; for (int i = 0; i < 10; i++) { positions[i] = pos; rot = rotAdd * rot; pos += rot * Vector3.up * 25f; }
(I'm doing this in UI space obviously but you get the point)
I guess that anglePerPoint here would come from your rotation gizmo
@tacit shuttle are u sleep bro haha
Hmm, thanks for this. And after thinking about it more, and looking at this. I realized it isn't just a rotation issue but a position issue. Like, yours works, but also requires you to override the position completely.
So, while keeping the offset, I am not sure there is a good way to do it without just looping over them all multiple times like I am. Well, I guess you can probably do the math for the loops instead.
Just had to step away for a couple of minutes ๐
The thing with this type of implementation is that the distance between the points no longer stays equal. I appreciate the effort though ๐
summary you just want optimize loop?
After thinking about it more. And with some of the snippet Osmal gave. I think I know what I need and how to implement it. Thanks!