Skip to main content

Java

Implementing HCTM in Java

In this post, we implement the Homogeneous Coordinate Transformation Matrix (HCTM) in Java. HCTM is a fundamental concept in robotics and computer graphics for representing rotation and translation of a coordinate frame in 3D space. Using a 4×4 matrix allows both rotation and translation to be combined into a single matrix multiplication, making it efficient to apply multiple transformations in sequence. What is HCTM? A Homogeneous Coordinate Transformation Matrix extends a standard 3D rotation matrix to 4×4 by appending a translation vector and a homogeneous row [0 0 0 1]. This program implements three rotations (Yaw around X-axis, Pitch around Y-axis, Roll around Z-axis) and one translation. Given a rotation angle (in degrees) and a 4-element coordinate frame vector, the program computes the transformed frame using matrix–vector multiplication.

Implementing Direct Kinematics in Java

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.

Implementing DFS in Java

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.

Implementing BFS in Java

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 Example in Java

Learn Java inheritance with a clear, hands-on example. See how a Box class extends Rectangle using the extends keyword and super() constructor chaining, with a full code walkthrough, sample output, and FAQs.

Polymorphism Example in Java

Learn Java polymorphism with clear examples of both method overloading (compile-time) and method overriding (runtime). Includes step-by-step walkthroughs, sample output, and FAQs covering dynamic dispatch, @Override, and static method hiding.

Finite State Machine: Check Whether a Number is Divisible by 3

Learn how to build a Finite State Machine (FSM) in Java that checks whether a decimal number is divisible by 3. Includes the theory behind the digit-sum rule, a 3-state FSM implementation, state-trace output, sample output, and a detailed explanation.