contrat a line
contrat a line
i have a line with the start and the end point. I need to reduce the length of 40px. How? Thanks
I think you need to be more specific.
However, from what I am getting you have a line and you want to only draw it up to 40px long.
This should do that: (I am assuming 2D since you said pixels)
I don't know if this is the best way to do it, but it should work!
~DtD
However, from what I am getting you have a line and you want to only draw it up to 40px long.
This should do that: (I am assuming 2D since you said pixels)
Code: Select all
irr::core::vector2di a(2,100);
irr::core::vector2di b(100,300);
irr::f32 dir = atan2f(b.Y-a.Y,b.X-a.X);//Get the direction between the two points
irr::core::vector2di bfinal(cosf(dir)*40,sinf(dir)*40);//Get where b would be (in relation to 0,0) 40px in direction dir
bfinal+=a;//Translate it to a to it puts it in the right place
//Just a test drawing thing to show it working:
irrDevice->getVideoDriver()->draw2DLine(a,b);
irrDevice->getVideoDriver()->draw2DLine(a,bfinal,video::SColor(255,255,0,0));
~DtD
thanks for the answer
the problem is this:
i have two points: vector3df(x1,y1,z1) and vector3df(x2,y2,z2)
for example the line that connects these two points is long 200px. Now i need to find the end point of the line that starts in vector3df(x1,y1,z1), point to vector3df(x2,y2,z2) and is long 160px.
Thanks for the help
the problem is this:
i have two points: vector3df(x1,y1,z1) and vector3df(x2,y2,z2)
for example the line that connects these two points is long 200px. Now i need to find the end point of the line that starts in vector3df(x1,y1,z1), point to vector3df(x2,y2,z2) and is long 160px.
Thanks for the help
vec1 (start)
vec2 (end)
vec3 (from vec1 to vec2)
vec3 = vec2 - vec1
Since you know the length of vec3 (200 units) you do this:
vec3.normalize() * 160
So its length is 160 and finally:
vec3 += vec1
Now vec3 should be what you want.
If you don't know the length of vec3 you can easily calculate it:
|vec3| = squareroot( pow(x,2) + pow(y,2) + pow(z,2) )
However, you should also check the Irrlicht API since there are lots of functions already built in. For instance:
getDistanceFrom
normalize
getLength
setLength
vec2 (end)
vec3 (from vec1 to vec2)
vec3 = vec2 - vec1
Since you know the length of vec3 (200 units) you do this:
vec3.normalize() * 160
So its length is 160 and finally:
vec3 += vec1
Now vec3 should be what you want.
If you don't know the length of vec3 you can easily calculate it:
|vec3| = squareroot( pow(x,2) + pow(y,2) + pow(z,2) )
However, you should also check the Irrlicht API since there are lots of functions already built in. For instance:
getDistanceFrom
normalize
getLength
setLength