Я пытался добиться явного euler в моем коде chole blackhole, который делается в ue4. Я хотел бы реализовать явный эйлер с черной дырой, чтобы каждую секунду он расходился наружу. основа c идея в том, что каждую секунду ошибка увеличивается на ххх, например (0,00012 или что-то). черная дыра отталкивает маленьких актеров (ящиков). Я также хотел бы интегрировать таймер в него. 10-секундный таймер, чтобы каждую секунду я мог видеть ошибку кода Эйлера, представляющего с силой (сила увеличивается каждую секунду), а на 10-й секунде он разрушает (черная дыра).
У меня есть часть кода, готовая у меня есть разместил это ниже. Любое предложение о том, как я мог бы все это перемешать, будет благодарно.
[компоненты для черной дыры установлены, внешняя сфера - это радиус, который притянет коробки в черную дыру
Фактическая черная дыра код, который делает ящики go в лунку
basi c настройка кода Эйлера в другом проекте для целей тестирования
// Consider a differential equation
// dy/dx=(x + y + xy)
float func(float x, float y)
{
return (x + y + x * y);
}
float func1(float x, float y)
{
// f(x,y) = 3e-x - 0.4y
double e = 2.71828f;
float val = 0.4f;
double exp1 = exp(x);
float X;
float Y;
std::pow(exp1, -x);
double algorithm = 3 * std::pow(exp1, -x) - 0.4* y;
return (algorithm);
}
void euler(float x0, float y, float h, float x)
{
float temp = -0;
// Iterating till the point at which we
// need approximation
while (x0 < x) {
temp = y;
y = y + h * func(x0, y);
x0 = x0 + h;
}
// Printing approximation
cout << "Approximate solution at x = "
<< x << " is " << y << endl;
}
int main()
{
// y' = x - y
// y' = dx/dy
// dx = -y
// dy = x
// - y / x = x - y
// xy - y = x²
// y*(x - 1) = x²
// y = x² / (x - 1)
// y' = x - x²/(x-1)
// = x² - x - x² / (x - 1)
// = -x / (x - 1)
// double t, y[N];
// int j;
float time = 10.0f;
// Initial Values
float x0 = 0;
float y0 = 1;
float h = 0.1;
float x = 0.1;
// Value of x at which we need approximation
euler(x0, y0, h, x);
system("PAUSE");
return 0;
}
нереальный код двигателя, я хотел бы интегрировать эйлер код в черную дыру и проверить, как в 3D-видении, как выглядит ошибка. Любые идеи, как я мог бы интегрировать это в черную дыру?
ABlackHole::ABlackHole()
{
// Set this actor to call Tick() every frame. You can turn this off to
improve performance if you don't need it.
PrimaryActorTick.bCanEverTick = true;
// setting the variables
//Origin = MeshComp->SetWorldLocation()
Radius = 200.0f;
Strenght = 100.0f;
bAccChange = false;
Force = 50.0f;
Acceleration = 9.8f;
// setting mesh
MeshComp = CreateDefaultSubobject<UStaticMeshComponent>(TEXT("MeshComp"));
MeshComp->SetCollisionEnabled(ECollisionEnabled::NoCollision);
RootComponent = MeshComp;
// setting the smaller sphere
InnerSphereComponent = CreateDefaultSubobject<USphereComponent>
(TEXT("InnerSphereComp"));
InnerSphereComponent->SetSphereRadius(100);
InnerSphereComponent->SetupAttachment(MeshComp);
InnerSphereComponent->OnComponentBeginOverlap.AddDynamic(this,
&ABlackHole::OverlapInnerSphere);
// setting the bigger spehre to attrach objects
OuterSphereComponent = CreateDefaultSubobject<USphereComponent>
(TEXT("OuterSphereComp"));
OuterSphereComponent->SetSphereRadius(3000);
OuterSphereComponent->SetupAttachment(MeshComp);
}
void ABlackHole::OverlapInnerSphere(UPrimitiveComponent*
OverlappedComponent, AActor* OtherActor, UPrimitiveComponent* OtherComp,
int32 OtherBodyIndex, bool bFromSweep, const FHitResult& SweepResult)
{
if (OtherActor)
{
OtherActor->Destroy();
}
}
void ABlackHole::Tick(float DeltaTime)
{
Super::Tick(DeltaTime);
//will be using many component of same types so tarray will be handy
TArray<UPrimitiveComponent*> OverlappingComps;
OuterSphereComponent->GetOverlappingComponents(OverlappingComps);
for (int32 i = 0; i < OverlappingComps.Num(); i++)
{
UPrimitiveComponent* primcomp = OverlappingComps[i];
if (primcomp && primcomp->IsSimulatingPhysics())
{
//needs simulation in order to apply force
const float sphereRadius = OuterSphereComponent-
>GetScaledSphereRadius();
const float ForceStrenght = -2000; //neg value to pull
//const float ForceStrenght = 2000; //pos value to push
primcomp->AddRadialForce(GetActorLocation(), sphereRadius,
ForceStrenght, ERadialImpulseFalloff::RIF_Constant, true);
//primcomp->(GetActorLocation(), NAME_None , true);
//FVector Impulsee;
//Impulsee.IsUniform(DeltaTime);
//primcomp->AddAngularImpulse(Impulsee, NAME_None, false);
}
}