Specifically, I want to make a part point towards the players x, y, and z coordinates. Is there a math equation that I can use? Or maybe something along those lines?? Thank you
Try using:
YourPart.CFrame = CFrame.lookAt(YourPart.Position, Player.Position)
Related
So I have a pretty simple question regarding the size of my data. I am trying to calculate the distance between all sets points (WGS84) in a dataset (56000).
https://www.rdocumentation.org/packages/geosphere/versions/1.5-10/topics/distm
According to the documentation: distm(x,y,fun="") if missing, y is the same as x
mydist<-distm(coordinates(mySpatialObject), fun="distHaversine")
This led me to an Error that y was missing. So I figured I could easily work around this.
distm(coordinates(WeedClim.plot),coordinates(WeedClim.plot), fun="distHaversine")
This leads to not just R:Studio, but my entire computer freezing. I had to to a hard reset twice now and do not want to go through this again, because this is my dissertation and I am afraid of breaking something else in the project XD.
Any ideas/solutions? Is there a better function that gives me a distance matrix from a set of coordinates?
THANKS!
I have a data set of XYZ coordinates (lake bathymetry) and I want to create a grid out of them for later meshing purposes using GMSH. I know that there is an easy way to do it in MATLAB using the boundary(x,y,z) function. Unfortunately, I couln't find anything similar in R and I have too many points to create boundary lines by hand.
Does anyone has an idea how to proceed with this in R? At the end I need the lines consisting of the outer points in my point cloud.
Thanks a lot!
You can try using chull which finds the convex hull.
From the chull help
X <- matrix(stats::rnorm(2000), ncol = 2)
chull(X)
plot(X[,1],X[,2])
points(X[chull(X),1],X[chull(X),2],col=2,pch=19)
I don't understand the concept of Vector3.Angle in Unity.
Can someone please explain in detail of what it does and how it works?
It would also be really awesome if you could provide some diagrams for me understand it more, visually.
It's very straight forward, Vector3.angle. takes 2 parameters, to and from. Essentially returns the angle that's generated from one position, to another. An example would be var characterDirection would be the "from" parameter, and lets say var enemyPosition would be the "to" parameter, and it will generate an acute angle. Hope this helps, also Unity has a great scripting API you should check it out.
The first thing to understand is what a vector is. A vector is a mathematical quantity that has both a magnitude and direction. For the purpose of this question, we don't care about the magnitude but you can think of a vector as an arrow pointing in some direction.
Now, you might be confused how we draw an arrow using only Vector3(x, y, z). While you might more commonly use a Vector3 to represent a point in 3D space, it is of course also used as a vector, as the name suggests. The thing is, if you try to call Vector3.Angle(transform1.position, transform2.position) you're going to get some weird results because it's expecting vectors, not positions even though they use the same object type.
Therefore, you should instead do something like
Vector3 direction = transform2.position - transform1.position;
float angle = Vector3.Angle(direction, transform1.forward);
forward is just a shorthand for a vector along the z-axis, so this would be like looking at an angle in 2D space.
I just started using Mathematica and came across a problem. I would like to solve more elegantly. I have measurement data in {x,y,z} form and want to transform these into sperical coordinates. I know how to do it using simple functions. But the code gets ugly.
I would like something like:
v={x,y,z}
TranformSpherical[v]
I have looked in the documentation and only found something for version 9, I am using 8 and it did not work when I tried it. Also I have not found a clear solution anywhere else. Hope someone here knows a simple solution to the probem.
The equations are given on Wikipedia and are simple function evaluations.
What's stopping you from simply computing them, and how does it get ugly?
Make sure to use ArcTan[x, y] in Mathematica, which computes the four-quadrant arctangent. For more information see the article about atan2.
In version 9
CoordinateTransformData["Cartesian" -> "Spherical", "Mapping", {x, y, z}]
gives you
{Sqrt[x^2 + y^2 + z^2], ArcTan[z, Sqrt[x^2 + y^2]], ArcTan[x, y]}
which expresses the three spherical coordinates in terms of {x,y,z}
CoordinateTransform["Cartesian" -> "Spherical", {x, y, z}]
will give you the same thing, but can also be used for conversion.
If you have a list {{x0,y0,z0},{x1,y1,z1},...} of Cartesian coordinates, you can apply CoordinateTransform like this
cartesianList = RandomReal[{0, 1}, {4, 3}];
CoordinateTransform["Cartesian" -> "Spherical", #] & /# cartesianList
In earlier versions
<< Calculus`VectorAnalysis`
SetCoordinates[Spherical]
There is a notebook at the mathworld.wolfram.com site page for Spherical Coordinates. Close to the beginning is an example for what you are doing.
I have a large set of 3D data points to which I want to fit to an ellipsoid.
My maths is pretty poor, so I'm having trouble implementing the least squares method without any math libraries.
Does anyone know of or have a piece of code that can fit an ellipsoid to data which I can plug straight into my project? In C would be best, but it should be no problem for me to convert from C++, Java, C#, python etc.
EDIT: Just being able to find the centre would be a huge help too. Note that the points aren't evenly spaced so taking the mean won't result in the centre.
here you go:
This paper describes fitting an ellipsoid to multiple dimensions AS WELL AS finding the center for the ellipois. Hope this helps,
http://www.physics.smu.edu/~scalise/SMUpreprints/SMU-HEP-10-14.pdf
(btw, I'm assuming this answer is a bit late, but I figured I would add this solution for anyone who stumbles across your question in search for the same thing :)
If you want the minimum-volume enclosing ellipsoid, check out this SO answer for a bounding ellipsoid.
If you want the best fitting ellipse in a least-squares sense, check out this MATLAB code for error ellipsoids where you find the covariance matrix of your mean-shifted 3D points and use that to construct the ellipsoid.
Least Squares data fitting is probably a good methodology give the nature of the data you describe. The GNU Scientific Library contains linear and non-linear least squares data fitting routines. In your case, you may be able to transform your data into a linear space and use linear least-squares, but that would depend on your actual use case. Otherwise, you'll need to use non-linear methods.
I could not find a good Java based algorithm for fitting an ellipsoid, so I ended up writing it myself. There were some good algorithms for an ellipse with 2D points, but not for an ellipsoid with 3D points. I experimented with a few different MATLAB scripts and eventually settled on Yury Petrov's Ellipsoid Fit. It fits an ellipsoid to the polynomial Ax^2 + By^2 + Cz^2 + 2Dxy + 2Exz + 2Fyz + 2Gx + 2Hy + 2Iz = 1. It doesn't use any constraints to force an ellipsoid, so you have to have a fairly large number of points to prevent a random quardic from being fit instead of the ellipsoid. Other than that, it works really well. I wrote a small Java library using Apache Commons Math that implements Yury Petrov's script in Java. The GIT repository can be found at https://github.com/BokiSoft/EllipsoidFit.
We developed a set of Matlab and Java codes to fit ellipsoids here:
https://github.com/pierre-weiss
You can also check our open-source Icy plugin. The following tutorial can be helpful:
https://www.youtube.com/endscreen?video_referrer=watch&v=nXnPOG_YCxw
Note: most of the existing codes fit a generic quadric and do not impose an ellipsoidal shape. To get more robustness, you need to go to convex programming rather than just linear algebra. This is what is done in the indicated sources.
Cheers,
Pierre
Here is unstrict solution with fast and simple random search approach*. Best side - no heavy linear algebra library required**. Seems it worked fine for mesh collision detection.
Is assumes that ellipsoid center matches cloud center and then uses some sort of mirrored average to search for main axis.
Full working code is slightly bigger and placed on git, idea of main axis search is here:
np.random.shuffle(pts)
pts_len = len(pts)
pt_average = np.sum(pts, axis = 0) / pts_len
vec_major = pt_average * 0
minor_max, major_max = 0, 0
# may be improved with overlapped pass,
for pt_cur in pts:
vec_cur = pt_cur - pt_average
proj_len, rej_len = proj_length(vec_cur, vec_major)
if proj_len < 0:
vec_cur = -vec_cur
vec_major += (vec_cur - vec_major) / pts_len
major_max = max(major_max, abs(proj_len))
minor_max = max(minor_max, rej_len)
It can be improved/optimized even more at some points. Examples what it will produce:
And full experiment code with plots
*i.e. adjusting code lines randomly until they work
**was actually reason to figure out this solution
I have an idea. Approximately solution, not the best but will keep points inside. In XY plane find the radius R1 that will obtain all points. Same do for the XZ plane (R2) and YZ plane (R3). Then use the maximums on each axes. A=max(R1,R2), B=max(R1,R3) and C=max(R2,R3).
But, first of all find the average (center) of all points and align it to origin.
I have just gone through the same process.
Here is a python module which is based on work by Nima Moshtagh. Referenced in many places but also in this question about a Bounding ellipse
This module also handles plotting of the final ellipsoid. Enjoy!
https://github.com/minillinim/ellipsoid/blob/master/ellipsoid.py
I ported Yury Petrov's least-squares Matlab fitter to Java some time ago, it only needs JAMA: https://github.com/mdoube/BoneJ/blob/master/src/org/doube/geometry/FitEllipsoid.java