-
March 26th, 2022, 05:25 PM
#1
C++: how get line points?
using the line point origin and destination, we can calculate the line dots between origin and destination:
Code:
#define M_PI 3.14159265358979323846 /* pi */
struct Position2D
{
Position2D()
{
//Nothing;
}
Position2D(float X, float Y)
{
PosX = X;
PosY = Y;
}
float PosX = 0;
float PosY = 0;
};
struct Position3D
{
float PosX = 0;
float PosY = 0;
float PosZ = 0;
Position3D()
{
//Nothing;
}
Position3D(float X, float Y, float Z)
{
PosX = X;
PosY = Y;
PosZ = Z;
}
operator Position2D()
{
Position2D Pos2D{PosX, PosY};
Pos2D.PosX = PosX;
Pos2D.PosY = PosY;
return Pos2D;
}
};
std::vector<Position3D> GetLinePoints(Position3D Origin, Position3D Destination)
{
//Getting the Line Points Count:
int LineCountPoints = sqrt(abs(Destination.PosX - Origin.PosX) * abs(Destination.PosX - Origin.PosX)
+ abs(Destination.PosY - Origin.PosY) * abs(Destination.PosY - Origin.PosY)
+ abs(Destination.PosZ - Origin.PosZ) * abs(Destination.PosZ - Origin.PosZ));
//Get the increment for X, Y and Z:
Position3D Increment;
Increment.PosX = (Destination.PosX - Origin.PosX) / LineCountPoints;
Increment.PosY = (Destination.PosY - Origin.PosY) / LineCountPoints;
Increment.PosZ = (Destination.PosZ - Origin.PosZ) / LineCountPoints;
Position3D NextPoint=Origin;
std::vector<Position3D> GetPoints;
for(int LinePoint =0 ; LinePoint<LineCountPoints; LinePoint++)
{
//Get the next point:
NextPoint.PosX += Increment.PosX;
NextPoint.PosY += Increment.PosY;
NextPoint.PosZ += Increment.PosZ;
//Round the values:
Position3D Pos3D;
Pos3D.PosX = round(NextPoint.PosX);
Pos3D.PosY = round(NextPoint.PosY);
Pos3D.PosZ = round(NextPoint.PosZ);
//Add the 3D position on vector:
GetPoints.push_back(Pos3D);
}
return GetPoints;
}
my problem is some point\pixel can be more 1 X or Y... how can i precise more the line points?
see these red line:
(i use the rotation calculation for rotate the origin and destination)
can i make it more precise?
i need be more precise for fill a rectangle without black pixels... can anyone advice me?
-
March 27th, 2022, 04:11 AM
#2
Re: C++: how get line points?
Some questions to your post:
1. What do you mean by "precise" / "more precise"?
2. What do you mean by "line dots / points"?
3. If you just want to "fill a rectangle" the why not use FillRect function?
Victor Nijegorodov
-
March 27th, 2022, 11:46 AM
#3
Re: C++: how get line points?
Originally Posted by VictorN
Some questions to your post:
1. What do you mean by "precise" / "more precise"?
2. What do you mean by "line dots / points"?
3. If you just want to "fill a rectangle" the why not use FillRect function?
hello VictorN.. sometime
1 - the line be printed more clear(mean the perfect line);
2 - the line is printed using the pixels positions... the positions must be calculated. the 'GetLinePoints()' do the job.
3 - because the FillRect() don't draw like the 3D.. we must use the same height, but on 3D it can be different.
https://imgur.com/Ftpb6H9
-
March 27th, 2022, 02:11 PM
#4
Re: C++: how get line points?
see these image:
the line can be more precise? is more like a stairs than a line
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|