#find vector

1 messages Β· Page 1 of 1 (latest)

rotund ferry
#

Hi, guys I have 2 points and want to find the third point what has a certain angle and magnitude... how can I do it ?

cursive cape
rotund ferry
#

?

cursive cape
#

point2-point1 this would give the vector from point1 to point2, which isn't what I said,
imagine like a pendulum, you swing the vector point2ToPoint1 around point2 so point2 has to be the origin

#

why? because it exactly gives you the direction of the vector you ask for?

#

to get the vector from p2 to p3 is literally
take the vector p2 to p1,
rotate it by 60 degrees,
change the magnitude to 5

#

well actually both would work, but if you do it with (point2-point1), you need to negate the angle in a way (-60) and also change the sign of the vector (invert it later) again

#

sounds more complex, would work too, but why go through that effort

rotund ferry
#

thanks !

#

just to be clear

#

this is what are you saying... right?

#

I think it should be y=60 πŸ˜…

cursive cape
#

it's in 3d=

#

?

#

well not that it matters much

#

after you calculated myVector, you miss the step where you add the second point to it

#

if you want it to be relative to point2

#

and i dont get your angle check

#

why do you use point2ToPoint1 as rotation base vector but then compare the angle against point1ToPoint2? after you applied the rotation

#

i don't know your project so i dunno which axis you need

#

if it's 2d it is likely the z axis

#

but for 2d you can look up simpler algorithms to rotate a vector2 i believe

#

(well simpler in terms of processing, not really in terms of code). doesnt really matter though, quaternion multiplication should be fine

rotund ferry
#

I am just forcing the c point (cube) to have atleast 60degree angle

#

if its less than 60 then make it 60

#

that kind of logic

#

if its more than 60 don't do anything

cursive cape
#

ah I see, so you need the x rotation in that case

#

I am still confident that my suggested logic should be fine

#

for your initial question

rotund ferry
#

lemme try to rotate on x axis. for now I am getting bizzare result from the code πŸ˜… . must be me doing something wrong

cursive cape
#

if L should be below, maybe try to invert the angle (angle * -1f)

#

or just adding the minus in front

#

in your screenshot looks like it should be z but it can also be that you have local axis transformation movement enabled, which would show the local axis gizmos, not the global ones

rotund ferry
#

wait lemme send a full screenshot

#

its from top view

#

and indeed its set to local

cursive cape
#

ah yeah local

#

okay, so from the global gizmos, seems like you look for the y rotation

#

z is up, x is right,
so y would be the depth axis

rotund ferry
#

yeah, I am using y axis but some reason the code is giving wrong vector.
the point you mentioned to add second point

#

I didn't get that

#

but lemme try anyways

#

now it looks fine?

cursive cape
#

yeah, just that the angle check makes 0 sense

rotund ferry
cursive cape
#

before you added point 2, you had a relative vector (imagine as if it had the origin of (0,0))

now you have the absolute point 3
but then you compare the angle of some point to point vector, which you also inverted, to a point (you'd need 2 relative vectors)

sorry i already started typing, just for clarification ^^

rotund ferry
#

myVector is coming out huge....

#

can you see something wrong?

cursive cape
#

does rider show all the values like that? that's neat

rotund ferry
#

yeah, it does 😁

#

am i multiplying angle and vector correctly

#

?

cursive cape
#

no clue why it comes out that way

#

quaternion multiplication looks right to me

#

and quaternion.euler returns a quaternion not a vector so no idea what happens here

rotund ferry
#

this is what it returns

cursive cape
#

yeah seems fine

#

i should go now though, good luck with that!
alternatively, just get the c# code for rotating a 2d vector and apply that to the x and z components of your vector for the rotation