MAR (Machine of Attack & Return). V.01 ( THIS IS TOY R/C LEVEL DEVICE, NOT A REAL WEAPON )
Inverse Kinematic in 10 min. from YouTube
2024.01.19 16:27
// I got following reference code from this https://www.youtube.com/watch?v=ZAge9pUM6do&t=254s
let shoulder = {
x: 100,
y: 300
}
let elbow = {
x: 200,
y: 200
}
let hand = {
x: 300,
y: 250
}
function setup() {
createCanvas(400, 400);
upperArm = dist(shoulder.x, shoulder.y, elbow.x, elbow.y)
forearm = dist(elbow.x, elbow.y, hand.x, hand.y)
}
function draw() {
background(220);
strokeWeight(2)
fill(255)
line(shoulder.x, shoulder.y, elbow.x, elbow.y)
line(elbow.x, elbow.y, hand.x, hand.y)
circle(shoulder.x, shoulder.y, 20)
circle(elbow.x, elbow.y, 20)
fill(100, 255, 100)
circle(hand.x, hand.y, 20)
if(mouseIsPressed){
if(dist(mouseX, mouseY, hand.x, hand.y) < 20){
hand.x = mouseX;
hand.y = mouseY
elbow = ik(shoulder, hand, forearm, upperArm)
}
}
strokeWeight(0.5)
line(shoulder.x, shoulder.y, hand.x, hand.y)
line(shoulder.x, shoulder.y, 400, shoulder.y)
}
function ik(a, b, A, B) {
let C = dist(a.x, a.y, b.x, b.y)
let th = acos( (B**2 + C**2 - A**2) / (2*B*C) )
let phi = atan2(-(b.y - a.y), b.x - a.x)
return {
x: a.x + B*cos(th + phi),
y: a.y - B*sin(th + phi)
}
}

Comment 0
| No. | Subject | Author | Date | Views |
|---|---|---|---|---|
| 10 | New software resources | me | 2024.02.20 | 103 |
| 9 | Simple Attraction & Repulsion of Swarm practice | me | 2024.02.01 | 103 |
| 8 |
My Simple 2D Inverse Kinematics with BGRABitmat library [2]
| me | 2024.01.21 | 133 |
| 7 |
My Simple 2D Inverse Kinematics with BGRABitmat library [1]
| me | 2024.01.20 | 112 |
| 6 |
Inverse Kinematic with AI
| me | 2024.01.19 | 118 |
| » |
Inverse Kinematic in 10 min. from YouTube
| me | 2024.01.19 | 133 |
| 4 | My notebook system camera test | me | 2024.01.19 | 104 |
| 3 |
Binocular Cam
| me | 2024.01.14 | 105 |
| 2 | Object Pascal with MPU-9250 | me | 2023.10.06 | 110 |
| 1 |
Intro (Keeps changing)
| me | 2023.09.28 | 118 |