#Getting all the points between 2 3D vectors

10 messages · Page 1 of 1 (latest)

dim torrent
#

Hello, this is more of a math question I guess, but I have two 3D vectors and I've managed to calculate the distance between them. How can I use this to get all the points between using steps?
this is what I have so far

    public List<Vec> getPointsBetween(Vec start, Vec end) {
        double diffX = end.xCoord - start.xCoord;
        double diffY = end.yCoord - start.yCoord;
        double diffZ = end.zCoord - start.zCoord;
        
        double distance = Math.sqrt(diffX * diffX + diffY * diffY + diffZ * diffZ);

        List<Vec> points = new ArrayList();
        
        while(distance >= 0.0) {
            
        }
    }
patent havenBOT
#

This post has been reserved for your question.

Hey @dim torrent! Please use /close or the Close Post button above when you're finished. Please remember to follow the help guidelines. This post will be automatically closed after 300 minutes of inactivity.

TIP: Narrow down your issue to simple and precise questions to maximize the chance that others will reply in here.

shrewd raptor
# dim torrent Hello, this is more of a math question I guess, but I have two 3D vectors and I'...

What you are basically asking for is a line connecting the two points. As you already have the two points this is not that complicated. You will have to define one point as the start of your line. This point "shoots" a ray in the direction of the other point. The point you defined as the beginning of the line and the ray define the line between the two points. I'll give you an example how you could calculate the vector equation of a line.

P1(1 | 2 | 3); P2(2 | 5 | 8)
The general equation is as follows: 
λ = a scalar
p = any point your line should go through
p1 = the second point your line should go through

l : x = p + λ*(p1-p)

in our case

l : x = (1,2,3) + λ * (1,3,5)

Now if you replace λ with any number between 0 and 1 you will get a point between your two defined points (which can be in indefinitely small steps). If λ = 0 you will get p. If λ = 1 you will get p1. If λ is anything other than any value in the defined bounds, you will get a point that is on the projected path of the ray but not within p and p1
dim torrent
#

I'm gonna experiment a bit

shrewd raptor
shrewd raptor
dim torrent
shrewd raptor
#

you're welcome 🙂