Rotation matrix for a bicycle - graphics

Assume you have a flat plane, with a bicycle resting on it. As the bicycle enters a turn, it leans into the turn with angle theta. At the same time, the bike frame points in the same direction as the bike velocity.
Thus, given the bike velocity vector v (assumed to be in the XZ plane) and the lean angle theta, how can you find the rotation matrix for the bike?

Use a quaternion. Axis is bike velocity and 'lean into turn' is axis angle.
Then convert to rotation matrix

Related

Compute points at a given geodesic distance on a mesh

Repeating this question for better visibility. I have a triangular mesh (assume a manifold mesh). I want to sample corners of a square on a mesh that is independent of the triangulation.
I am following these steps
Sample a triangle (based on the areas of the triangles)
Sample a point uniformly on the triangle/face
Sample a pair of random perpendicular directions
I want to calculate the distance of three other corners of the square given an edge length. Since the corners can be on any other face, the output should be of the format (Face, barycentric coordinates on that face).
I am looking at libraries such as Polyscope or pygeodesic that use the heat method to compute the geodesic distance between two vertices of the mesh, but I am not sure how to get points at an arbitrary geodesic distance from another point.

How to represent orientation of rigid body in space with quaternions if roll is zero

I am trying to represent the orientation of a rigid body, say a pencil in 3 dimensional space with respect to fixed XYZ axes, originating at a fixed origin O. I am trying to visualize arriving at the quaternion representing the orientation of the pencil, by thinking in terms of the axis vector of the pencil's current orientation(i.e axis), and the roll on its own central lengthwise axis, (Following equation for quaternion from axis-angle representation is from Wikipedia).
Now as per my understanding if the roll of the pencil is zero, then the vector part of the quaternion vanishes, since sin(theta/2) shall become zero, and the resulting quaternion no longer has information of horizontal and vertical tilt with respect to the fixed axes. How I can describe the orientation of the pencil using quaternions in cases where the roll of the pencil is zero.
It is clearer if we imagine that the quaternion specifies the rotation from the default orientation of the pencil to its present orientation. One way of specifying this would be to assume that default orientation of the pencil is along the extrinsic X axis, with the default roll being zero when the label face is on the top. Now one possible way to describe the present orientation of the pencil is by the following three rotations:
Rotation about the Z, axis by the yaw angle
Rotation about the new Y axis, by the pitch angle
Rotation about the new X axis, by the roll
The combination of these three rotations, obtained by their quaternion product , will give us the quaternion of the pencil's present orientation, even if the roll, pitch or yaw is zero.

Cartesian to Latitude/Longitude

I have a 3D model of a 10km x 10km topographic map which I've imported from sketch-up , the model is just a bunch of X,Y,Z points (where X+ is the north and Z+ is straight up, perpendicular to the ground)
I know the Latitude Longitude values of the (0,0,0) point. So given a X,Y,Z point how do I get its Latitude Longitude values?
I need to be pretty accurate so you can't assume the earth is a perfect sphere (you can however assume it's an ellipsoid)
For best accuracy you need to know what map projection the map was drawn in. You should be able to find that out from the map. For example in the UK the Ordnance Survey maps use the OSGB36 datum, and the projection is Transverse mercator. The projection tells you how to convert geographic (lat,long for the datum ellipsoid) coordinates to map coordinates (easting and northing) and how to do the reverse calculation, which is pretty much what you want.
If you don't know the projection, the next best thing would be if you could find out -- again from the map, they are often written on it -- the scale-factor and convergence of the projection at some points on the map. The point is that there is usually a slowly spatially varying difference between map north (the direction the north axis points in) and true north (the direction of the north pole from a point, the direction of the latitude axis) and there is always a slowly spatiallty varying scale factor, the ratio of a distance in map coordinates and the true distance. Note that this not the same thing as the scale of the printed map (an inch to a mile or whatever), it is a property of the projection.
Over a 10km square, it would be reasonably accurate to treat both the scale and convergence as constants. Then given an x,y point you compute the map bearing from 0,0 using
b = atan2(x,y)
and convert this to a true bearing by subtracting the convergence.
You also compute the map distance by
r = hypot(x,y)*S
where S is the scale of the map, e.g. if your a change of 1 in x coordinates represents a distance of 100m, S is 100
and convert r to a true distance by dividing by the scale-factor.
Finally you want to compute the lat,long a given distance and bearing from a given point (the lat,long of 0,0). An accurate way to do this is to use Vincenty's formulae.
One thing to note here is that the scale and convergence, if quoted on the map will be relative to the ellipoid used in construction of the map, so you will be computing lat,long coordinates for that ellipsoid.

Finding two points' center of mass on a sphere (k-means on a sphere)

Please, help me to solve subproblem in my programming task (k-means clustering on a sphere).
Suppose the Earth is a sphere. And there are two points (we know their latitudes and longitudes) with masses m_1 and m_2 on it.
The problem is to find latitude and longitude of these two points' center of mass on a sphere, if the distance is measured as the great-circle distance.
You want to find a point that lies on the great circle arc at distance
l = L * m1 / (m1 + m2)
from the first point, where L is full distance between points.
You can use or
spherical linear interpolation : translate spherical coordinates to Descartes' coordinate system, work with vectors, translate back
or
geodesic approach - find bearing from the first point to the second, find distance L, and move distance l with bearing found. All formulae are at this page: Destination point given distance and bearing from start point

How to find points in a certain distance to a Latitude/Longitude Coordinate

I'm working with Latitude/Longitude Coordinates and i'm trying to find an equation for a circle on the surface that includes all points that have a certain distance(on the surface) from the center.
It's important that this should work also with very big distances (for example half the perimeter of the earth), so the flat-earth approximation probably won't work, but assuming it's a perfect sphere is okay.
Can anybody help?
Thanks in advance!
I have this very same problem.
What I do is to convert the latitude and longitude to Cartesian coordinates fixed at the center of the Earth (which I assume is spherical).
I interpret these coordinates as a mathematical vector.
I also convert the desired "distance from center of circle"
to an angle at the center of the Earth,
that is, if the distance is d then the angle is alpha = d/R
where R is the Earth's radius.
I then find three vectors.
The first vector, v1, is just cos(alpha) times my original vector,
that is, it points from the center of the Earth to the center of my circle
and it has length R*cos(alpha).
The other two vectors, v2 and v3, have length R*sin(alpha),
and they are both perpendicular to v1 and to each other.
I can then get any point on the desired circle by taking
v1 + cos(beta)*v2 + sin(beta)*v3
where beta can range from 0 to 2*pi.
Finally, if I want the latitude and longitude of that point,
I convert it back from Cartesian coordinates.
If you never actually care about the Cartesian coordinate model but will
instead use only the latitudes and longitudes that result,
you can simplify the procedure slightly by assuming R == 1.
You can then simplify the formulas so that you never have to define
the variable R.
The coordinate conversions in either direction can be fairly straightforward.
An easy way to find vector v2 is to take the x and y coordinates of v1
(ignoring z), rotate the resulting vector 90 degrees in the x-y plane
(so if you started with (x,y,z), the new vector is (-y,x,0)),
and then scale the vector to the desired size.
Of course if the x and y coordinates of v1 are zero then you can
let v2 be any vector in the x-y plane.
To get v3 you can take the cross product of v1 and v2 and scale
as desired.

Resources