Calculate eulerRotation for Node
-
Hi, i need a little help with something in my 3D project.
I need something like a map ping to point to the center of my Sphere in my QtQuick3D project.
I was able to locate the rotation responsible for rotating the Node object which is 'eulerRotation'.
So here is the information that I have about my point on the surface of sphere:Node{ position: calculatedPosition() eulerRotation{ x: ? y: ? z: ? } //Properties property int radiusEarth: 1180 property real latitude: 0 property real longitude: 0 Node { Image { anchors.centerIn: parent width: 200 height: 200 source: "qrc:/3DGlobe/textures/Hexagon_LightGreen.png" } } //Functions function calculatedPosition(){ var latitude_rad = latitude * Math.PI / 180; var longitude_rad = longitude * Math.PI / 180; var zPos = radiusEarth * Math.cos(latitude_rad) * Math.cos(longitude_rad); var xPos = -radiusEarth * Math.cos(latitude_rad) * Math.sin(longitude_rad); var yPos = radiusEarth * Math.sin(latitude_rad); return Qt.vector3d(-xPos+5, yPos+5, zPos+5) } }
-
Hi, i need a little help with something in my 3D project.
I need something like a map ping to point to the center of my Sphere in my QtQuick3D project.
I was able to locate the rotation responsible for rotating the Node object which is 'eulerRotation'.
So here is the information that I have about my point on the surface of sphere:Node{ position: calculatedPosition() eulerRotation{ x: ? y: ? z: ? } //Properties property int radiusEarth: 1180 property real latitude: 0 property real longitude: 0 Node { Image { anchors.centerIn: parent width: 200 height: 200 source: "qrc:/3DGlobe/textures/Hexagon_LightGreen.png" } } //Functions function calculatedPosition(){ var latitude_rad = latitude * Math.PI / 180; var longitude_rad = longitude * Math.PI / 180; var zPos = radiusEarth * Math.cos(latitude_rad) * Math.cos(longitude_rad); var xPos = -radiusEarth * Math.cos(latitude_rad) * Math.sin(longitude_rad); var yPos = radiusEarth * Math.sin(latitude_rad); return Qt.vector3d(-xPos+5, yPos+5, zPos+5) } }
@md2012 said in Calculate eulerRotation for Node:
I need something like a map ping to point to the center of my Sphere in my QtQuick3D project.
I don't understand what you're trying to achieve, please elaborate.
I was able to locate the rotation responsible for rotating the Node object which is 'eulerRotation'.
Use aTransform
to rotate the node.
https://doc.qt.io/qt-5/qml-qt3d-core-transform.htmlJust noticed this is QtQuick3D, so my comment is useless, disregard.
-
Let's say we have 3D pin like this one:
And we need to put it on a sphere (Earth model).
First thing we are going to need to calculate where to put our pin on the earth surface, which is now working perfectly using the above code.
The problem is that the pin is not pointing to the center of the sphere and we are going to need some calculation for rotation as well. -
Let's say we have 3D pin like this one:
And we need to put it on a sphere (Earth model).
First thing we are going to need to calculate where to put our pin on the earth surface, which is now working perfectly using the above code.
The problem is that the pin is not pointing to the center of the sphere and we are going to need some calculation for rotation as well.@md2012 said in Calculate eulerRotation for Node:
The problem is that the pin is not pointing to the center of the sphere and we are going to need some calculation for rotation as well.
You realize that this is an impossible task, right? Your system is underdetermined, that is even if the pin's butt is pointing away from the center (of your sphere) all rotations around the radius vector (or in the local coordinates, around the z-axis of the pin) are equally correct. You need more information - typically a vector to fix the actual orientation.
-
@md2012 said in Calculate eulerRotation for Node:
The problem is that the pin is not pointing to the center of the sphere and we are going to need some calculation for rotation as well.
You realize that this is an impossible task, right? Your system is underdetermined, that is even if the pin's butt is pointing away from the center (of your sphere) all rotations around the radius vector (or in the local coordinates, around the z-axis of the pin) are equally correct. You need more information - typically a vector to fix the actual orientation.
Looks like latitude and longitudes were enough to calculate the right angle for the marker to point to the center of the sphere.
Here is the final result:Node{ position: calculatedPosition() eulerRotation{ x: 180-latitude y: longitude z: 0 } //Properties property int radiusEarth: 1180 property real latitude: 0 property real longitude: 0 Node { Image { anchors.centerIn: parent source: "qrc:/3DGlobe/textures/Hexagon_LightGreen.png" } } //Functions function calculatedPosition(){ var latitude_rad = latitude * Math.PI / 180; var longitude_rad = longitude * Math.PI / 180; var zPos = radiusEarth * Math.cos(latitude_rad) * Math.cos(longitude_rad); var xPos = -radiusEarth * Math.cos(latitude_rad) * Math.sin(longitude_rad); var yPos = radiusEarth * Math.sin(latitude_rad); return Qt.vector3d(-xPos-10, yPos+10, zPos+10) } }
My pointer is 2d so this could need a 180 degree rotation with a 3d pin.