Inkonsistente Ergebnisse mit meinem C# Fast Voxel -Traversal -Algorithmus (Amanatides und Woo)C#

Ein Treffpunkt für C#-Programmierer
Anonymous
 Inkonsistente Ergebnisse mit meinem C# Fast Voxel -Traversal -Algorithmus (Amanatides und Woo)

Post by Anonymous »

Ich versuche, diesen Algorithmus in C#zu implementieren, aber ich habe im Moment sehr inkonsistente Ergebnisse, und ich kann nicht herausfinden, warum.public static IEnumerable
FastVoxelTraversal(Point a, Point b)
{
var ret = new List();

Vector direction = ((Vector)b - (Vector)a);

int stepX = direction.x >= 0 ? 1 : -1;
int stepY = direction.y >= 0 ? 1 : -1;
int stepZ = direction.z >= 0 ? 1 : -1;

var iterator = a;

float nextVoxelBoundaryX = (iterator.x + stepX);
float nextVoxelBoundaryY = (iterator.y + stepY);
float nextVoxelBoundaryZ = (iterator.z + stepZ);

float tMaxX = (direction.x != 0) ? (nextVoxelBoundaryX - a.x) / direction.x : float.MaxValue;
float tMaxY = (direction.y != 0) ? (nextVoxelBoundaryY - a.y) / direction.y : float.MaxValue;
float tMaxZ = (direction.z != 0) ? (nextVoxelBoundaryZ - a.z) / direction.z : float.MaxValue;

float tDeltaX = (direction.x != 0) ? 1f / direction.x * stepX : float.MaxValue;
float tDeltaY = (direction.y != 0) ? 1f / direction.y * stepY : float.MaxValue;
float tDeltaZ = (direction.z != 0) ? 1f / direction.z * stepZ : float.MaxValue;

while (iterator != b)
{
if (tMaxX < tMaxY)
{
if (tMaxX < tMaxZ)
{
iterator.x += stepX;
tMaxX += tDeltaX;
}
else
{
iterator.z += stepZ;
tMaxZ += tDeltaZ;
}
}
else
{
if (tMaxY < tMaxZ)
{
iterator.y += stepY;
tMaxY += tDeltaY;
}
else
{
iterator.z += stepZ;
tMaxZ += tDeltaZ;
}
}

ret.Add(iterator);
}

return ret;
}
< /code>
Die Zellgröße beträgt 1. Wie Sie sehen können, sind die Ergebnisse manchmal wie erwartet und manchmal nicht. src = "https://i.Sstatic.net/zobhfc95.png"/>

Was soll ich korrigieren? < /p>
Vielen Dank. Ich habe die Ergebnisse gemalt, die ich erwarte:

Dieser Algorithmus sollte eine "Supercover" ausführen, was bedeutet, dass es alle Zellen enthalten sollte. Dies unterscheidet sich von Bresenham, das eine approxative Rasterisierung ergeben soll.

Quick Reply

Change Text Case: 
   
  • Similar Topics
    Replies
    Views
    Last post
  • Inkonsistente Ergebnisse mit Pandas Styler ApplyMap
    by Anonymous » » in Python
    0 Replies
    1 Views
    Last post by Anonymous
  • Kennzeichen Erkennungsproblem - inkonsistente Ergebnisse
    by Anonymous » » in Python
    0 Replies
    1 Views
    Last post by Anonymous
  • Sonarqube Java Path Traversal Attack
    by Guest » » in Java
    0 Replies
    5 Views
    Last post by Guest
  • Dezimalartikelmenge im Woo [Duplikat]
    by Anonymous » » in Php
    0 Replies
    8 Views
    Last post by Anonymous
  • JSON Volley -Bounce -Fehler für die WOO Mobile App
    by Anonymous » » in Android
    0 Replies
    6 Views
    Last post by Anonymous