Herman Geschrieben 3. Juli 2023 Geschrieben 3. Juli 2023 (bearbeitet) Hello, I need some help. How can I get the value of the rotation (over z) of an object ? ( Lua is fine, angle or rad is ok ) And then on some conditions, rotate it to another angle. (over z) Thanks in advance. Kind regards, Herman Bearbeitet 3. Juli 2023 von Herman
prinz Geschrieben 3. Juli 2023 Geschrieben 3. Juli 2023 Hello @Herman , Seems that in Lua rad is used. To try it, place a "Schalter" (button, switch, ??) and create an event on it (example, i used a BR 80 for tests): print ($("BR 80").transformation.rotation.z) $("BR 80").transformation:rotateZ(0.25) I hope, that may help you. Kind regards, Wolfgang
Herman Geschrieben 3. Juli 2023 Autor Geschrieben 3. Juli 2023 (bearbeitet) 57 minutes ago, prinz said: print ($("BR 80").transformation.rotation.z) Hello, thanks, but this value is not the angle ( z ) in radians of that object. ( convert with math.deg print and see ). The second one : $("BR 80").transformation:rotateZ(0.25) is known by me and does correct the job for that angle in rad. ( I sometimes use it , to rotate further over x rad) Kind regards , Herman Bearbeitet 3. Juli 2023 von Herman
Herman Geschrieben 4. Juli 2023 Autor Geschrieben 4. Juli 2023 Hello, since ( I think ) there is not an easy solution for my question (for now), and I'm not looking for some formulas, see further under "feature request". Kind regards, Herman
simonjackson1964 Geschrieben 5. Juli 2023 Geschrieben 5. Juli 2023 I've given this a try, and I honestly cannot figure out what the values held in (Object).transformation.rotation represent... They are not consistent - it's as if the values are stored as text but held as real numbers (or vice versa), so when you retrieve the value you only get part of it. Try setting X, Y and Z rotations to 0, 90 and 180, and print the three different values, then change them to 90, 180 and 0 respectively and do it again. The values are totally inconsistent. Especially odd is the one that should be zero is in fact not zero!
Hawkeye Geschrieben 5. Juli 2023 Geschrieben 5. Juli 2023 (bearbeitet) Am 3.7.2023 um 17:50 schrieb Herman: How can I get the value of the rotation (over z) of an object ? ( Lua is fine, angle or rad is ok ) And then on some conditions, rotate it to another angle. (over z) Hello @Herman, maybe this basic example (one of my experiments) will help you to find answers. Rotationstest per Lua-Anweisung.mbp (Sorry, it is not translated to english) Kind regards, Hawkeye PS: The Transformation only works in global koordinates, not in local koordinates of the vehicle Bearbeitet 5. Juli 2023 von Hawkeye
Goetz Geschrieben 5. Juli 2023 Geschrieben 5. Juli 2023 vor einer Stunde schrieb simonjackson1964: I honestly cannot figure out what the values held in (Object).transformation.rotation represent... The values which you get when you use Lua are called quaternions. They are not the same as those which you find in the object's positioning table. Here's a Wikipedia article describing the basics and the purpose. I can't give you any more information because I didn't find the nerve to delve deeper into the subject.
Hawkeye Geschrieben 6. Juli 2023 Geschrieben 6. Juli 2023 Hello @Herman, the interpretation of the values presented in the example above may be difficult to understand. But for the rotation you will always get the values back in the global coordinate system. These do not change, so they are always the same. You want the z-rotation value of the local coordinate system relative to the global coordinate system. This value is probably not available in lua. Kind regards, Hawkeye
Herman Geschrieben 6. Juli 2023 Autor Geschrieben 6. Juli 2023 (bearbeitet) 15 hours ago, Hawkeye said: (Sorry, it is not translated to english) Hello, @Hawkeye , thanks for the support. I'll have a look at your example. No sorry at all. We all can use Google translate here. Recent I too only work in one language here, however English. My German is not good enough. 1 hour ago, Hawkeye said: This value is probably not available in lua. Yes, I already said that is probably so, that's why I went to "feature request". 13 hours ago, Goetz said: The values which you get when you use Lua are called quaternions. Hello, @Goetz , thanks for the reaction at @simonjackson1964 , yes I know. And I'm not looking to some formulas to find it, only if it should be easy available. Since Neo uses the quaternion to rotate, and shows the values in positioning, maybe ... ? But I repeat, an exotic request, and maybe the users will never want to use it. Kind regards, and thanks again. After looking at Hawkeye's example more toroughly , maybe I'll come back here. Herman Bearbeitet 6. Juli 2023 von Herman typo
Herman Geschrieben 6. Juli 2023 Autor Geschrieben 6. Juli 2023 Hello @Hawkeye , thanks for your example. It is the global angle that I need, not the local. A question : when we change from global to local or vice versa, only the view of the axises changes. ( to move stable along an axis if wanted ), but the values we see in positioning for the angles are only the global one. ( correct ? ) I have remarks on your example, but it takes a while to explain this correct. I learned already a lot out of your example, so thank you. See you again here. Kind regards, Herman
Goetz Geschrieben 6. Juli 2023 Geschrieben 6. Juli 2023 vor 8 Minuten schrieb Herman: the values we see in positioning for the angles are only the global one. correct. The world is a fixed reference and you can always declare an objects position relative to this fix point. The object itself would be a fleeting reference. Any value could only reflect the difference between before and after. The moment you let go of the object, the current position would become the new reference and all values would go back to 0.
Herman Geschrieben 6. Juli 2023 Autor Geschrieben 6. Juli 2023 (bearbeitet) 26 minutes ago, Goetz said: correct. The world is a fixed reference and you can always declare an objects position relative to this fix point. Thank you @Goetz so I did understand that. Now the remarks on @Hawkeye 's example print("globale Objekt-Rotation:") print("Rotation(rad) um x =",FZahl(Rotation.x,2), "y =", FZahl(Rotation.y,2), "z =", FZahl(Rotation.z,2), "w =", FZahl(Rotation.w,2)) print("Rotation(Grad)um x =",FZahl(math.deg(Rotation.x),2), "y =", FZahl(math.deg(Rotation.y),2), "z =", FZahl(math.deg(Rotation.z),2), "w =", FZahl(math.deg(Rotation.w),2)) I do not agree with this formulas. You only take the x, y, z, w from the Quaternion. Conversing to radials or degrees is a lot more complicated. But why not some pictures , what I mean is : start rotate with your program over x 15° The pictures are correct, your example does the job, but : So I still cannot find in Lua ( see the prints ) the wanted angle before or after the rotation. Hawkeye, but I appreciate it a lot you wanted to give some help. Let us leave it for now at "feature request". Kind regards, Herman Bearbeitet 6. Juli 2023 von Herman
Hawkeye Geschrieben 6. Juli 2023 Geschrieben 6. Juli 2023 Hello @Herman, vor 7 Minuten schrieb Herman: I do not agree with this formulas. For explanation. I created the above example in MBS version V7. The possibility of changing from the object global to local system did not work in V7. It's a new feature since V8. vor 13 Minuten schrieb Herman: Conversing to radials or degrees is a lot more complicated. Yes, that is correct. It is only a test print to get the program values before and after a rotation. vor 9 Minuten schrieb Herman: So I still cannot find in Lua ( see the prints ) the wanted angle before or after the rotation. That is what i wanted to tell you. You only get the values of the global system (0,0,0) not the difference between both systems that (0,0,-45) values of rotation in the window vor 3 Stunden schrieb Hawkeye: But for the rotation you will always get the values back in the global coordinate system. These do not change, so they are always the same. vor 32 Minuten schrieb Herman: The pictures are correct, your example does the job, Not really, i wanted the rotation to be done in the local system not in the global one. I wanted to achieve that. But it didn't work. Kind regards, Hawkeye
Herman Geschrieben 6. Juli 2023 Autor Geschrieben 6. Juli 2023 (bearbeitet) 1 hour ago, Hawkeye said: ou only get the values of the global system Hello @Hawkeye . The 45° in my picture is the angle in the global system. ( we see it at positioning ). It is seen after your rotation of -15°. It started at 60°. 1 hour ago, Hawkeye said: Not really, i wanted the rotation to be done in the local system not in the global one. I wanted to achieve that. But it didn't work. Ok you wanted that, and did not achieve that; I did not know it. But I'm only interested in the angles vs the global system. So it did correct the -15° rotation in the global system. And I cannot find in Lua the 60° or the 45° for a specific object in the global system. But will we please leave it now ... Kind regards, Herman Bearbeitet 6. Juli 2023 von Herman
EASY Geschrieben 6. Juli 2023 Geschrieben 6. Juli 2023 Hello, vor 2 Stunden schrieb Herman: Conversing to radials or degrees is a lot more complicated. function quaternion_to_euler(x, y, z, w) local winkel={} winkel.x= math.atan(2*(w*x+y*z), 1-2*(x^2+y^2)) local t2=2*(w*y-z*x) if t2>1 then t2=1 end if t2<-1 then t2=-1 end winkel.y = math.asin(t2) winkel.z = math.atan(2*(w*z+x*y), 1-2*(y^2+z^2)) local cc = x*y+z*w if cc > 0.499999 then winkel.x = 2 * math.atan(x, w) winkel.z = math.pi/2 winkel.y = 0 elseif cc < -0.499999 then winkel.x = -2 * math.atan(x, w) winkel.z = -math.pi/2 winkel.y = 0 end winkel.x=math.deg(winkel.x) winkel.y=math.deg(winkel.y) winkel.z=math.deg(winkel.z) return winkel end local w=$("Coupé").transformation.rotation local we=quaternion_to_euler(w.x,w.y,w.z,w.w) local text="" text="x="..string.format("%.4f", we.x).."°".."\n" text=text.."y="..string.format("%.4f", we.y).."°".."\n" text=text.."z="..string.format("%.4f", we.z).."°" $("Textfeld1").text=text Quaternion to euler.mbp Kind regards EASY
Herman Geschrieben 6. Juli 2023 Autor Geschrieben 6. Juli 2023 1 hour ago, EASY said: function quaternion_to_euler(x, y, z, w) Hello @EASY , for such a nice solution thank you very much. I'm very happy with that. Kind regards, Herman
Empfohlene Beiträge
Erstelle ein Benutzerkonto oder melde dich an, um zu kommentieren
Du musst ein Benutzerkonto besitzen, um einen Kommentar verfassen zu können
Benutzerkonto erstellen
Neues Benutzerkonto für unsere Community erstellen.
Neues Benutzerkonto erstellenAnmelden
Du hast bereits ein Benutzerkonto? Melde dich hier an.
Jetzt anmelden