Move line until it hits a collection of points [closed] - c#

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 7 years ago.
Improve this question
I have an imaginary line segment (I have the start and end of the segment) and a List of Points. I want to move this line closer to the collection of points until it hits one of them. This image should make things clearer:
In this image I want to move the green line to the red points until it hits them and get the blue line.
So I have Point startGreen, endGreen; and List<Point> redPoints. How can I get Point startBlue, endBlue;?

Follow these steps:
Calculate distance between each point and the green line
find minimum distance
move green line to the point with minimal distance
-- OR --
Find a coordiante transformation which rotates the green line to (say) the y-axis.
Transform all points
find the point with the largest x-component
Move the green line to this point.
Do the inverse trsnafomation

Related

Unity How to create a procedural tube mesh [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 5 years ago.
Improve this question
I want to create a procedural mesh like you can see in the following picture:
Unfortunately I have no idea how to do that. Can anyone of you help me out?
I think I know how to create the mesh of the tube, but I do not know how to create those circles.
The following is a rough overview of how to edit the vertices of a mesh, but for more details this link might help you.
List<Vector3> vertices = new List<Vector3>();
List<int> triangles = new List<int>();
GenerateMesh(vertices, triangles);
Mesh mesh = gameObject.GetComponent<MeshFilter>().mesh;
mesh.vertices = vertices.ToArray();
mesh.triangles = triangles.ToArray();
In terms of actually generating your mesh, I would suggest generating N points in a circle on a plane, this is your start point. Then repeatedly move the plane forward slightly, rotate it, and generate more points. Each time connect the points to the previous set of points generated to make your triangles.

How to reduce space between points in a line chart? [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 5 years ago.
Improve this question
How do I reduce space between points in a line chart in C#. I would like to reduce the space between the points 01 and 02 and 03, it is very big. the red line is for show the space what I want to reduce.
Not sure what you want.
If you want the tick marks to appear more frequently, you will need to manipulate the Axis.MajorTickMark property.
If you like the tick marks where they are data-wise, but want them closer together, you can manipulate the Axis.Minimum property and the Axis.Maximum property. The larger the range covered by the axis, the closer together the tick marks will become.
If you want to keep the axis range the same and the tick mark values the same, your only option is to make the chart itself smaller, which will make everything closer together.
If you want to keep the minimum, maximum, chart size, and tick mark values the same, but just want them closer together, that is physically impossible, if you think about it.

Moving the player tile by tile smoothly in Unity [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 4 years ago.
Improve this question
I want to make the player move by a specific amount (1 tile/unit in this case) and then stop him. Just like in this video:
http://www.youtube.com/watch?v=DotOAbNngc4
By pressing a key the player should move smoothly to the next tile, than stops and so on.
How can I archieve this? (in C#)
You could take a look at GridMove which is from UnifyWiki.
You would probably get more of a response if you posted this question to answers.unity3d.com or forum.unity3d.com as these forums are specifically target towards Unity3d.
Here's what I would do: you give your player class a target field, e.g. a 2d vector. This will either contain the current position of the player (when initializing or when the target has been reached) or the target that you want to move the player to.
Now in your update you do this:
if target equals your current position then check user input for movement.
if user requests movement set target to position adjacent to current position.
else slowly move player towards target.
You may want to create a field for the current position of the player besides the normal position in GameObject. You could then update GameObject.position in the update-cylce by a small delta until the positions of GameObject.position and target have the (roughly! use epsilon when comparing) same value.
Some hints
Vector2.MoveTowards can help you
To check if the target and position are "close enough" you could subtract one from the other and look at the resulting vector's magnitude.
Beware of overshooting when you move towards the target. If your movement distance is more then or equal to the distance between position and target, just set the position to the target.

Get xyz coordinates from starting point, quaternion and moved distance [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
In my case I have a starting coordinate x,y,z, an orientation in Quaternion and I know the moved distance.
Basically I would like to know the x',y',z' after applying the transformation and the forward movement. So I am trying to move a point in 3D using quaternion. I guess it should be just a simple calculation but for some reason I cannot find the solution that easily.
In previously I converted the Quaternion to Euler angles and used them to calculate the x',y',z'. Unfortunately because of the Gimbal lock this solution is not suitable for me anymore.
I have found a few example for example this one in python and here's an other in C#, but I still did not get the formula of them as they are discussing the rotation instead of the movement it self, the C# example just changes the middle point of the cube and then it redraws it with the rotation.
Why reinvent the wheel ? This kind of operation is best handled via matrixes - and C# has even support for it.
// PresentationCore.dll
using System.Windows.Media.Media3D;
Matrix3D matrix = Matrix3D.Identity;
matrix.Translate(new Vector3D(x, y, z));
matrix.Rotate(quaterion);
var newPoint = matrix.Transform(point);

Quickly checking whether two line segments are from the same line [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
I have two edges, both of which are made up of 2 3-dimensional points, forming a line segment.
Is there a relatively quick way of checking whether both of the line segments part of the same line?
Let's first segment has end points A,B , and second segment has end points C,D. Both segments belong to the same line, if
AB x AC = AB x AD = 0 (vector product)
How to do it depends on how your segments are represented, but an idea would be:
check they are collinear ( ie no intersection )
Length of the candidat must be smaller or equal
then check for start or end being on the potential container

Categories