How to link curves [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 4 years ago.
Improve this question
First of all, let me make it clear that I don't know much about programming. So after I got that out of the way, thanks for reading my question.
So what I currently want to cram into my little C# programm is the following:
Draw a line from pA to pX
Draw a curve from pX to pY
Draw a curve from pY to pZ
Draw a line from pZ to pD
My problem with this is the following:
How on earth do I "switch" from a line to a curve, to another curve and then back to a line in C#?
I'd be really happy if anyone could help me with this.
Greetings from Belgium,
-g2609

Seems you want to provide smooth connection of line segments and curves.
Note that Bezier curves at the end points have direction (tangents) to control points. So just put control points at the continuation of straight segments. Distance from the enpoints to the control ones is responsible for curvature. Try to use values like distXY / 3 to start.
For curve-curve connection you have to define some rule. For example, define tangent direction (and maginute again). If you need smooth curve chain, consider interpolation splines - this approach calculates cubic curves parameters for all curves and provides continuity.
Pseudocode for line A-X, cubic Bezier X-Y, line Y-Z.
VecAX = X - A
uAX = (VecAX.X / VecAX.Length, VecAX.Y / VecAX.Length)
curveXY.P0 = X
curveXY.P1 = X + uAX * VecAX.Length / 3
curveXY.P2 = Y - uXZ * VecXZ.Length / 3
curveXY.P3 = Y

Related

I'm writing an algorithm to determine if someone has been hit by a bullet or not [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 last month.
Improve this question
Bullet
I've been thinking about it for a while,
but I can't find an answer, so I'm asking a question.
I'm making a game with C# opengl(opentk).
At first, I tried to search the coordinates of the bullet for each pixel to see
if it hit the enemy.
That method required too extensive a search.
I'm not asking you to code.
Just need some tips.
Any help would be appreciated.
Rotate the scene so that the trajectory becomes vertical. This is done by applying the transformation
X' = ( u.X + v.Y) / √(u²+v²)
Y' = (- v.X + u.Y) / √(u²+v²)
to all points. ((u, v) defines the shooting direction.)
Now it suffices to check if
Xc' - R < Xo' < Xc' + R
and
Yo' < Yc'

How to get a down vector just from a normal vector? [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 3 years ago.
Improve this question
I have got a 3D game running. The red rectangle is my player on some kind of ramp or house roof. He is not rotated. Now when he falls on such a ramp I can get the green vector by the RaycastHit normal.
But what I want to get is the purple vector, so I can give my player the velocity to slide down. How do I get that vector or is it impossible with the variables given?
The purple vector is the closest vector to Vector3.down that is tangent to the roof.
Edit: I guess I figured out how to get to that Vector but I still don't understand how to calculate it. In the second picture vector a and b is given. Now I need to get vector c, which is 90 degrees from a to b.
Figured it out. If anyone is wondering: I just used the Vector3.RotateTowards like this:
rigid.velocity = Vector3.RotateTowards(hit.normal, -transform.up, Mathf.PI / 2, 0);
The vector you are looking for is the vector orthogonal to the normal of the surface that is closest to the direction of gravity (typically Vector3.down). You can use vector cross product to find this:
Vector3 surfaceNormal;
Vector3 directionOfGravity = Vector3.down;
Vector3 slopeSideways = Vector3.Cross(directionOfGravity, surfaceNormal);
if (slopeSideways != Vector3.zero)
{
Vector3 slopeDown = Vector3.Cross(surfaceNormal, slopeSideways).normalized;
}
else
{
// surface is normal to the direction of gravity, there is no downwards slope.
}

How to move an object to random coordinates 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 5 years ago.
Improve this question
I'am reviewing the code for the project.
What I want to do is the following picture.
I have some questions about the project.
As a beginner, I will not have enough explanation,
but I would appreciate it if you could give it a look.
Here are the questions:
How do I create an object called small_star as indefinitely, as shown in the picture?
Currently, prefab x, y coordinate values ​​are centered on the scene.
How do I move an object with random coordinates like a photo? And when I look at the code, I use Mathf.Cos and Mathf.Sin. What effect does it have?
I think I should implement it, but it is too much for me to do coding.
I'm a beginner. I would really appreciate it if you could give me a specific explanation.
You dont provide much information, but this may work
public GameObject small_star;
public float xMinBoundary;
public float yMinBoundary;
public float xMaxBoundary;
public float yMaxBoundary;
void MoveSpaceShip(){
float randX = Random.Range (xMinBoundary, xMaxBoundary);
float randY = Random.Range (yMinBoundary, yMaxBoundary);
Vector2 target = new Vector2 (randX,randY)
//Option 1
//small_star.transform.Translate(target * Time.deltaTime);
//Option 2
small_star.transform.position(target)
}
You will need to adapt to your needs

Collision of two balls in wpf and getting the paths of colliding balls [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
This question is regarding WPF.
I have two balls, one static and the other is moving towards the static ball. On collision the balls would move in the direction that would be decided by the collision that at which angle they would collide and move accordingly.
My question is basically for suggestions for what is the easiest and the most effective way of colliding the objects in WPF and after collision giving them a path to move accordingly. Apart from deceleration etc, what should be the best strategy that should be applied to DETECT collision and GIVE NEW PATHS TO THE BALLS AFTER COLLISION.
Simply figure out the distance of the centers of the 2 balls.
if (distance(ball1.Center, ball2.Center) <= ball1.Radius + ball2.Radius)
{
// collision
}
For the distance use this:
double x = ball1.Center.X - ball2.Center.X;
double y = ball1.Center.Y - ball2.Center.Y;
double distance = Math.sqrt(x*x + y*y); // pythagoras
For calculating the new directions you'll need some more math. Have a look for a geometrics library like it is delivered with XNA. Try googeling your question again and use XNA in the search instead of WPF - this will solve your problem, i guess.
I would calculate the distance (pythagoras) between them, if the distance is smaller than the two radius added, a collision occurs.
Check here for the angle between the points:
Math Calculation to retrieve angle between two points?
You could check this one:
Ball to Ball Collision - Detection and Handling

How to generate a bell curve (Gaussian function) [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 9 years ago.
Improve this question
I'd like to be able to generate a bell curve to use for probability in procedural generation in games.
For, example if I want to generate a forest, I could give it a radius and intensity and make a bell curve of the right shape to give me the probability of whether a tree should be placed or not. I should end up with a lot of trees in the centre and they would become less frequent as you approach the radius distance out from the centre.
I've done something similar before using a sine wave. But I have no idea how to make a bell curve. These equations are greek to me. I have forgotten how to read them, but it would be greek to the computer anyway.
Could someone write down the equation for bell curve in C# (or python would be my 2nd choice) and maybe explain it a bit?
Sure.
p(x) = exp(-(x-mu)^2/(2*sigma^2))/sqrt(2*pi*sigma^2)
The bell curve is also called the gaussian probability distribution. It is basically taking e to the power of a negative square of the x value. The rest is to make sure that it is centered at mu and scaled to the specifics of the particular problem you are modeling, and to make sure that the integral over all values of x sums to 1.
To generate random samples from this distribution in Python, you can do something like the following:
import random
sample = random.gauss(mu, sigma)
# where mu is the center of the bell curve, and sigma is proportional to its "width"
If you want to have a two-dimensional bell curve, it's nice to know that you can find X and Y values separately like in the above, and the 2D plot will be a 2D bell curve, where the density is highest at the center (mu_x, mu_y).

Categories

Resources