In this post, we implement Direct Kinematics (Forward Kinematics) for a SCARA robot in Java using the Denavit-Hartenberg (DH) convention. Direct kinematics determines the position and orientation of the robot’s end-effector (tool tip) given the joint angles and link parameters. This is the fundamental calculation in robot arm control and simulation.
What is Direct Kinematics?
For a multi-joint robot arm, each link between joints is described by four DH parameters:
θ (theta) — Joint angle (rotation about Z-axis)
d — Link offset (translation along Z-axis)
a — Link length (translation along X-axis)
α (alpha) — Link twist (rotation about X-axis)
For each link, a 4×4 General Link Coordinate Transformation Matrix (GLCTM) is computed from its DH parameters. The final end-effector pose is obtained by multiplying all the link matrices together: T04 = T01 × T12 × T23 × T34.
In this post, we implement Depth-First Search (DFS) in Java using an adjacency matrix and recursion. DFS is a fundamental graph traversal algorithm that starts at a source node and explores as far as possible along each branch before backtracking. It is used in cycle detection, topological sorting, maze solving, and AI game tree searches.
What is DFS?
DFS explores a graph by diving deep into one branch before exploring others. In this implementation, we use a recursive approach: starting from node 1, we immediately follow the first unvisited neighbour, then the first unvisited neighbour of that node, and so on. Only when we reach a dead end do we backtrack and try the next neighbour.
The graph is represented as an adjacency matrix. An array q[] is used both as the visited set and to record the traversal order. The variable qpos tracks how many nodes have been visited so far.
In this post, we implement Breadth-First Search (BFS) in Java using an adjacency matrix. BFS is a fundamental graph traversal algorithm that visits all nodes level by level, starting from a source node and exploring all its direct neighbours before moving deeper into the graph. It is widely used in shortest path problems, network analysis, and AI search strategies.
What is BFS?
BFS explores a graph by using a queue data structure. It starts at a chosen node (node 1 in our implementation), adds it to the queue, and then repeatedly dequeues a node, visits all its unvisited neighbours, and enqueues them. This guarantees that all nodes at depth d are visited before any node at depth d+1.
The graph in this implementation is represented as an adjacency matrix — a 2D array where m[i][j] = 1 means there is an edge between node i+1 and node j+1, and 0 means no edge.
Inheritance is one of the four pillars of Object-Oriented Programming (OOP) in Java. It allows a child class (subclass) to inherit the fields and methods of a parent class (superclass) using the extends keyword. This promotes code reuse, establishes an “is-a” relationship between classes, and forms the foundation for runtime polymorphism. In this post we walk through a practical example of single-level inheritance where a Box class extends a Rectangle class — reusing area logic while adding volume calculation on top of it.
Polymorphism — from the Greek for “many forms” — is one of the four pillars of Object-Oriented Programming in Java. It lets a single method name behave differently depending on the arguments it receives or the object it is called on. Java supports two types: compile-time polymorphism (method overloading, resolved by the compiler) and runtime polymorphism (method overriding, resolved dynamically at run time). In this post we look at hands-on examples of both, starting with the simpler overloading form and then showing how overriding works through inheritance.
A Finite State Machine (FSM) can determine whether a decimal integer is divisible by 3 without performing any division. The key insight is that a number is divisible by 3 if and only if the sum of its digits is divisible by 3. We can track the running digit-sum modulo 3 as we process each digit, mapping perfectly onto a 3-state FSM: State 0 (remainder 0), State 1 (remainder 1), and State 2 (remainder 2). After processing all digits, the machine is in State 0 if and only if the number is divisible by 3. The FSM also prints a state trace as it processes each digit.
A Finite State Machine (FSM) can be designed to recognise strings that end with a specific suffix. In this post, we build a 4-state FSM that accepts strings over the alphabet {a, b} which end with the suffix ‘abb’. Unlike the “contains” variant, here only the final state of the machine matters — the string is accepted if and only if the last three characters form ‘abb’. The FSM also prints a state trace showing each transition as it processes the input.