Building a Polar Point From Cartesian Coordinates
00:00 Building a Polar Point From Cartesian Coordinates. For a more elaborate example of providing multiple constructors using class methods, let’s say you have a class representing a polar point in a math-related application.
00:15 You need a way to make your class more flexible so that you can construct new instances using Cartesian coordinates as well. On-screen, you can see how to write a constructor to meet this requirement.
.from_cartesian() takes two arguments representing a given point’s
y Cartesian coordinates. Then the method calculates the required
angle to construct the corresponding
In these examples, you use the standard instantiation process and your alternative constructor,
.from_cartesian(), to create
PolarPoint instances using conceptually different initialization arguments.
Become a Member to join the conversation.