Notifications
Clear all
[Closed] rotating from center and normal
Page 2 / 2
Prev
Aug 03, 2015 4:33 pm
what do you know about cross and dot products?
the task is very simple for who knows what it is.
you have two vectors.
cross product makes an axis to rotate about
dot product makes a rotation angle
axis, angle and center makes rotation matrix, which being multiplied with origin point makes destination position
if as an origin point were used a matrix it makes rotation of whole object’s transform
2 Replies
I know the cross production is the vector which creates the up vector/ right angle of two vectors.
Not to familar with the dot product. Care to share knowledge?
Denis i took your feedback on what values needed to be calculated. Im not clear on how to create the variable which is multiplied to the original node. I was hoping you could elaborate a bit more to help me out. Thank you
fn GetVectorsAngle v1 v2 =
(
theAngle = acos(dot (normalize v1) (normalize v2))
)
fn PlaceAlongVector pos:[0,0,0] vec:[0,0,1] offset:0 =
(
pos + (normalize (vec)) * offset
)
fn GetCornerPoint posA:[0,0,0] posB:[0,0,0] =
(
/* Find the length to create a right traingle */
-- get angle difference between 2 vectors
difVector = posA - posB-- vector between plane and ball
objVector = pln.transform.row3 -- vector using normal of plane
dist = distance posB posA
calcAng = GetVectorsAngle difVector objVector
-- calculate the length of side to create a right angle
len = cos(calcAng) * dist
-- place point which would create a rightAngle at the sphere
cornerPos = PlaceAlongVector pos:posB vec:objVector offset:len
cornerPos
)
/* Test Scene Setup */
clearlistener()
format "
"
delete objects
pln = plane width:5 length:5 pos:[0,10,10] wirecolor:yellow
rotate pln (angleaxis 30 [1,0,0])
s1 = sphere pos:[25,40,0] wirecolor:red radius:2
s2 = sphere pos:[32,18,7] wirecolor:green radius:1
center = pln.pos
normal = pln.transform.row3
-- calculate corner positions which are then used to calculate correct vectors
p1 = GetCornerPoint posA:s1.pos posB:pln.pos
point pos:p1 size:2 wirecolor:(random yellow green)
p2 = GetCornerPoint posA:s2.pos posB:pln.pos
point pos:cornerPos size:2 wirecolor:(random yellow green)
-- angle between new vectors
vectorA = p1 - s1.pos
vectorB = p2 - s2.pos
ang = GetVectorsAngle vectorA vectorB -- ANGLE NEEDING TO ROTATE NODE
crs = cross vectorA vectorB -- AXIS TO ROTATE
I have this data but im not sure how to then use it to rotate the node correctly…
ang = GetVectorsAngle vectorA vectorB -- ANGLE NEEDING TO ROTATE NODE
crs = cross vectorA vectorB -- AXIS TO ROTATE
Aug 03, 2015 4:33 pm
soved this with some trig…
fn GetVectorsAngle v1 v2 =
(
theAngle = acos(dot (normalize v1) (normalize v2))
)
fn PlaceAlongVector pos:[0,0,0] vec:[0,0,1] offset:0 =
(
pos + (normalize (vec)) * offset
)
/* Test Scene Setup */
clearlistener()
format "
"
delete objects
pln = plane width:5 length:5 pos:[0,10,10] wirecolor:yellow
rotate pln (angleaxis 30 [1,0,0])
s1 = sphere pos:[0,30,0] wirecolor:red radius:2
center = pln.pos
normal = pln.transform.row3
/* Find the length to create a right traingle */
-- get angle difference between 2 vectors
difVector = s1.pos - pln.pos-- vector between plane and ball
objVector = pln.transform.row3 -- vector using normal of plane
dist = distance pln.pos s1.pos
calcAng = GetVectorsAngle difVector objVector
-- calculate the length of side to create a right angle
len = cos(calcAng) * dist
-- place point which would create a rightAngle at the sphere
cornerPos = PlaceAlongVector pos:pln.pos vec:objVector offset:len
point pos:cornerPos size:2 wirecolor:yellow
Page 2 / 2
Prev