Jump to content

Empfohlene Beiträge

Geschrieben (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)

rotation.jpg.7d420ed4b969b0e5d66f80255a5b2d07.jpg

Thanks in advance. Kind regards, Herman

Bearbeitet von Herman
Geschrieben

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

 

Geschrieben (bearbeitet)
  Am 3.7.2023 um 16:45 schrieb prinz:

print ($("BR 80").transformation.rotation.z)

Erweitern  

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 von Herman
Geschrieben

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

Geschrieben

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!

Geschrieben (bearbeitet)
  Am 3.7.2023 um 15: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)

Erweitern  

Hello Herman

maybe this basic example (one of my experiments) will help you to find answers. 

Screenshot2023-07-05191643.thumb.jpg.416eefc59009664af754522135b112ad.jpg

Rotationstest per Lua-Anweisung.mbpFetching info...


(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 von Hawkeye
Geschrieben
  Am 5.7.2023 um 17:20 schrieb simonjackson1964:

I honestly cannot figure out what the values held in (Object).transformation.rotation represent...

Erweitern  

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.

Geschrieben

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.

Screenshot2023-07-06083125.thumb.jpg.e39be4dcee542dacd174873dbc21458e.jpg

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.

Screenshot2023-07-06083312.thumb.jpg.2cc78aa11f2bc5a08728feb4715196f6.jpg

This value is probably not available in lua.

Kind regards, 

Hawkeye

Geschrieben (bearbeitet)
  Am 5.7.2023 um 17:27 schrieb Hawkeye:

(Sorry, it is not translated to english) 

Erweitern  

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.

  Am 6.7.2023 um 06:39 schrieb Hawkeye:

This value is probably not available in lua.

Erweitern  

Yes, I already said that is probably so, that's why I went to  "feature request". 

  Am 5.7.2023 um 18:41 schrieb Goetz:

The values which you get when you use Lua are called quaternions.

Erweitern  

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 von Herman
typo
Geschrieben

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

Geschrieben
  Am 6.7.2023 um 09:30 schrieb Herman:

the values we see in positioning for the angles are only the global one.

Erweitern  

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.

Geschrieben (bearbeitet)
  Am 6.7.2023 um 09:42 schrieb Goetz:

correct.
The world is a fixed reference and you can always declare an objects position relative to this fix point.

Erweitern  

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

hawkeye1.thumb.jpg.59bc24f23c9d75ad03901bf2389176bb.jpg

rotate with your program over x 15°

hawkeye2.thumb.jpg.00eb4c60377f8494ae51a5e5eedb15fb.jpg

The pictures are correct, your example does the job, but :

hawkeye3.jpg.547e8a6fc8f764ee4dc299610182299c.jpg

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 von Herman
Geschrieben

Hello @Herman, 

  Am 6.7.2023 um 10:03 schrieb Herman:

I do not agree with this formulas.

Erweitern  

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.

  Am 6.7.2023 um 10:03 schrieb Herman:

Conversing to radials or degrees is a lot more complicated.

Erweitern  

Yes, that is correct. It is only a test print to get the program values before and after a rotation.     

 

  Am 6.7.2023 um 10:03 schrieb Herman:

So I still cannot find in Lua ( see the prints ) the wanted angle before or after the rotation. 

Erweitern  

That is what i wanted to tell you. 

Screenshot2023-07-06120407.thumb.jpg.d7f0c9a5d6515684e1a3f976f805d342.jpg

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  

  Am 6.7.2023 um 06:39 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.

Erweitern  

 

  Am 6.7.2023 um 10:03 schrieb Herman:

The pictures are correct, your example does the job,

Erweitern  

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

Geschrieben (bearbeitet)
  Am 6.7.2023 um 10:42 schrieb Hawkeye:

ou only get the values of the global system

Erweitern  

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°.

  Am 6.7.2023 um 10:42 schrieb Hawkeye:

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. :/ 

Erweitern  

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 von Herman
Geschrieben

Hello,

  Am 6.7.2023 um 10:03 schrieb Herman:

Conversing to radials or degrees is a lot more complicated.

Erweitern  

Bild001.jpg.a091273521587d2092ff1e2f3d4e4b07.jpg

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.mbpFetching info...

Kind regards
EASY

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 erstellen

Anmelden

Du hast bereits ein Benutzerkonto? Melde dich hier an.

Jetzt anmelden
×
×
  • Neu erstellen...